473,403 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

CARRAY problem with ADD

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
0 1721

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ishira | last post by:
Hello, Please help. I am seriously at my wits end. Just when I feel I have completely understood copy contructor, I am stumped yet again. I have a class which has a CARRAY of objects. I am...
66
by: Mike Stenzler | last post by:
I am new to Template programming and I would like to create an array of user-defined class objects using MFC CArray. Normally I would use linked list processing - create an object class and then an...
0
by: Frank King | last post by:
Hi, I am using CArray and quick sort funciton to sort an array of double type of data points. I found an article in MSDN HOWTO: Quick Sorting Using MFC CArray-Derived Classes ID: Q216858 ...
5
by: Silly | last post by:
I have a legacy dll that has an important function that takes a CArray<WORD,WORD>& as it's only parameter. The dll is used by a number of internal applications and so can't be changed. I am...
1
by: db01092001 | last post by:
Hello, I'm interested in the internal organization of CArray, especially the execution time for the members, the operator respective: Determines the use of in constant time (O(1))? What about...
0
by: Josh McFarlane | last post by:
I'm currently reading raw data files for two arrays of floating point numbers. There are about 10k floating points per array per file, and I want to combine each file's arrays into a master...
4
by: danip | last post by:
Hi, I used to have the following: class CArchive { public: // create and specify the filename to use CArchive(CString filename, DWORD size); virtual ~CArchive(); CArchive& operator<<(bool...
10
by: fei.liu | last post by:
Consider the following sample code char * ptr = "hello"; char carray = "hello"; int main(void){ } What does the standard have to say about the storage requirement about ptr and carray? Is...
2
by: Dymus | last post by:
Ok here is sample of code: CArray <MyClass,MyClassarr; MyClass * obj; obj = new MyClass(); obj->some_field=some_value; arr.Add((*obj)); delete obj; ----
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.