Solved

How to Nest CArrays in Visual C++.NET

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can I "hot-patch" a hotpatchable C++ service exe on Windows Server? 9 335
Debug Error using Visual C++ 6.0 5 140
memorymap in visual studio 3 62
Find Visual Studio Tools 2 92
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 tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now