CARRAY problem with ADD

I

Ishira

Here is a snippet of my program. It is really intresting...

PREMISE:

Class CobjA has a private CARRAY memeber m_Arr of objects CobjB.

Class CobjB is a class with an int data variable called pWidth. CobjB
has a copy and an assignment constructor defined.

I am trying to add a CobjB to the private CARRAY member of CobjA.

Since I cannot access the m_Arr directly I have a function called

AddCobjBToArr(CObjB obj) defined in class CobjA

PROBLEM:

I get a heap pointer error when I do this

CobjA* A=new CobjA();

A->AddCobjBToArr(Cobjb(6));

I am honestly puzzled! Please help.


class CobjB: public CObject
{
public:

// Copy Constructor
CobjB(const CobjB &b);
const CobjB & operator= (const CobjB & b);

//Attributes
private:
int pWidth;

};
CobjB::CobjB(const CobjB& w)
{
pWidth=w.pWidth;
}

const CobjB& CobjB::eek:perator= (const CobjB& w)
{
pWidth=w.pWidth
return *this;

}

class CobjA: public CObject
{

private:
CArray<CobjB,CobjB&> m_Arr;
//Operations
public:
void AddCobjBToArr(CobjB b);


};

void CobjA::AddCobjBToArr(CobjB b)
{
m_Arr.Add(b); //Add CobjB to the private array
}

In the main function

CobjA *objA=new CobjA();
CobjA->AddCobjBToArr(CobjB(5));

Why does this result in a Debug Assertion Failed
_CrtlsValidHeapPointer???
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top