473,406 Members | 2,954 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,406 software developers and data experts.

CARRAY COpy constructor

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 trying to write a
copy constructor for the class and it's simply havoc! The array
variable is private to the class and simply contains objects without
dynamic variables.So no issue there. Just the very copying of CArray
is giving me problems.

Maybe some code on how you would handle it will help trmedously.

Kindly throw some light on the matter.

Thank you.
Ishi
Jul 19 '05 #1
2 4595
Ishira <is***********@yahoo.com> wrote in message
news:59**************************@posting.google.c om...
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 trying to write a
copy constructor for the class and it's simply havoc! The array
variable is private to the class and simply contains objects without
dynamic variables.So no issue there. Just the very copying of CArray
is giving me problems.

Maybe some code on how you would handle it will help trmedously.


First of all, only you can tell us what a CArray is, since it is not a
standard type. Also, you have not given any idea of what trouble you are
having.

Whatever CArray it is, suppose your class is called SomeClass and your
CArray member is called mArray, is there a reason that this won't work?

SomeClass::SomeClass(const SomeClass &c)
: mArray(c.mArray), // more copying
{}

DW

Jul 19 '05 #2

"Ishira" <is***********@yahoo.com> wrote in message
news:59**************************@posting.google.c om...
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 trying to write a
copy constructor for the class and it's simply havoc! The array
variable is private to the class and simply contains objects without
dynamic variables.So no issue there. Just the very copying of CArray
is giving me problems.

Maybe some code on how you would handle it will help trmedously.

Kindly throw some light on the matter.

Thank you.
Ishi


You should be using std::vector not CArray. At least you should if you want
to post to this group, since std::vector is a standard part of the C++
language, and CArray only exists in MFC. std::vector is also much better
designed than CArray, there is no problem copying std::vector objects.

#include <vector>

class B
{
...
};

class A
{
private:
std::vector<B> vec;
};

class A does not need a copy constructor, std::vector is well enough
designed that A will copy correctly with the compiler generated copy
constructor. That is not something that is true of CArray (I believe).

Time to learn some real C++, and leave MFC collection classes behind.

john
Jul 19 '05 #3

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

Similar topics

0
by: Ishira | last post by:
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...
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...
42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
15
by: A | last post by:
Hi, A default copy constructor is created for you when you don't specify one yourself. In such case, the default copy constructor will simply do a bitwise copy for primitives (including...
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...
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...
8
by: shuisheng | last post by:
Dear All, I am wondering how the default copy constructor of a derived class looks like. Does it look like class B : public A { B(const B& right) : A(right) {}
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.