Solved

How to Nest CArrays in Visual C++.NET

Posted on 2004-10-12
3
256 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
  • 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

856 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