Solved

How to Nest CArrays in Visual C++.NET

Posted on 2004-10-12
3
257 Views
Last Modified: 2010-05-18
From an earlier discussion (using VC++ 6)  I was told that in Visual C++.NET we could create nested CArrays without having to create a copy constructor
But in the following test I still get the error

error C2664: 'CArray<TYPE,ARG_TYPE>::Add' : cannot convert parameter 1 from 'ANG1' to 'ANG1'
        with
        [
            TYPE=ANG1,
            ARG_TYPE=ANG1
        ]
        No copy constructor available for class 'ANG1' or constructor attempts to perform illegal conversion to non-__gc reference

Howdo we nest CArrays in Visual C++.NET??

class ANG1
{
public:
      CArray <double,double> dAngs1;
};

class ANG2
{
public:
      CArray <ANG1,ANG1> dAngs2;
      
};

      double dAng = 1.0;
      ANG1 myAng1;
      myAng1.dAngs1.Add(dAng);
      ANG2 myAng2;

      myAng2.dAngs2.Add(myAng1);
0
Comment
Question by:MCofer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
OnegaZhang earned 250 total points
ID: 12294995
The following works, any way.

class ANG1
{
public:
      CArray <double> dAngs1;
      ANG1& operator=(const ANG1& a)
      {
            this->dAngs1.Copy(a.dAngs1) ;
            return *this;
      }
};

class ANG2
{
public:
      CArray <ANG1> dAngs2;

};
      double dAng = 1.0;
      ANG1 myAng1;
      myAng1.dAngs1.Add(dAng);
      ANG2 myAng2;

      myAng2.dAngs2.Add(myAng1);
0
 

Author Comment

by:MCofer
ID: 12295056
I can't find the MSDN note that said you didn't need a copy constructor in .NET for CArrays
As you can guess this is only a simple test. the actual copy constructors I have to create are large and the only reason it is necessary is one CArray.
If anyone can find any documentation on MSDN it would be very helpful.

You code works so I will gon ahead and accept the answer.


Thanks
0
 
LVL 12

Expert Comment

by:OnegaZhang
ID: 12295149
In my project, I would use CArray( ANG1*) since copy a struct is expensive.

Welcome to www.fruitfruit.com
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
linker errors gone with a clean build 2 61
Reinstalling MS Visual C++ redistributable packages 4 75
c++ open source accounting software 3 120
Visual c++ and text files 7 75
The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

697 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question