CARRAY COpy constructor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ishira

    #1

    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
  • David White

    #2
    Re: CARRAY COpy constructor

    Ishira <ishira_pundit@ yahoo.com> wrote in message
    news:595bee7e.0 308061648.6e877 436@posting.goo gle.com...[color=blue]
    > 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.[/color]

    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::Some Class(const SomeClass &c)
    : mArray(c.mArray ), // more copying
    {}

    DW



    Comment

    • John Harrison

      #3
      Re: CARRAY COpy constructor


      "Ishira" <ishira_pundit@ yahoo.com> wrote in message
      news:595bee7e.0 308061648.6e877 436@posting.goo gle.com...[color=blue]
      > 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[/color]

      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


      Comment

      Working...