When i compile my code i keep getting an error. *** glibc detected *** ./main: free(): invalid pointer: 0xbfb82c34 *** . I can not figure out for the life of me what the issue is. I think it may have something to do with my constructor. Any suggestions would be appreciated.

Employee* Earray[10];   // Declared as private member of payroll
Payroll::Payroll()
{
        Employee **EmpPointer;
        EmpPointer = new Employee*[10];

        for ( int i = 0; i < 10; i++ )
        {
               Earray[i] = 0;
        }
}

Payroll::~Payroll()
{
    delete [] Earray;
}

shouldnt you be deleting the memory allocated inside the ctor? That's a memory leak.

What does Earray point to? You've made it to null pointer: Earray[i] = 0 //like NULL And your EmpPointer is unused...
Seems like to me you're trying to allocate 2D array of some sort, but doing it wrong

Ok i figured out the error, it had to do with my destructor. The program compiles now but it is not working the right way. I believe i am trying to declare a 2-D array when i want to do a 1-D one but it's the only way i could get the code to compile. For my code i am supposed to have a Payroll class that will contain a fixed size array of pointers to Employee. The array must be processed polymorphically. Constructor: Creates Payroll with no employees.
Destructor: Cleans up as the object leaves scope. The Employee class is an Abstract Base Class. Here is my constructor.

Employee* Earray[10];   //Declared private member in Payroll
Payroll::Payroll()
{
        Employee **EmpPointer;
        EmpPointer = new Employee *[10];
        
}

>Here is my constructor.
Is that the whole of your constructor? If so, it's not accomplishing much of anything as you allocate memory to the local variable EmpPointer, and then proceed to leak memory when EmpPointer goes out of scope at the end of the constructor.

commented: Awesome avatar :) +5

It would be much better if you post the problem statement that you're trying to solve and also the complete code or atleast all the required and relevant code.

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.