Hello,

I am getting the follwoing error in my program:

*** glibc detected *** free(): invalid pointer

The program is as follows.

int main()
{
        operation1* sjob1 = new operation1();
        answer* ans1 = sjob1->execute();

        delete sjob1;

        operation2* sjob2 = new operation2();
        answer* ans2 = sjob2->execute();
        return 0;
}

I have the virtual member function execute() of the base class "operation" which is used by the derived classes -"operation1" and "operation2". I am getting th error at the following line in the code.

answer* ans2 = sjob2->execute();

The function execute() is a virtual function and the base class "operation" has all it member functions as virtual. I have tried deleting the object "ans1" also but i get a segmentaion fault if i do that.

Any help is appreciated.

Thanks

What's this?

operstion2

Is it a typo? Is it a global object declared in a file included in the program (ala cout or cin)?

Hi,

Sorry that is a typo. it is operation2

Thanks

Could you explain a bit more what you are trying to do? :)

operation1* sjob = new operation1();
answer* ans1 = operation1->execute();
delete sjob;

shouldn't you operate on sjob since you have created it? creating an object with new and then deleting it just seems like a waste :confused: or am I missing something?

I don't think you can call objects member functions without creating an object first (someone confirm this)

sorry for the incorrect code. I have corrected the code.

Can someone help me with possible cause of errors.

After correction, if this line

answer* ans1 = sjob1->execute();

works, but this line

answer* ans2 = sjob2->execute();

still doesn't work, there has to be an error in your class operation2.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.