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: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???
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: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???