By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,794 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

CARRAY problem with ADD

P: n/a
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::operator= (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???
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.