By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,836 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 COpy constructor

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.