Solved

How to Nest CArrays in Visual C++.NET

Posted on 2004-10-12
3
245 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
Comment Utility
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
Comment Utility
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
Comment Utility
In my project, I would use CArray( ANG1*) since copy a struct is expensive.

Welcome to www.fruitfruit.com
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

15 Experts available now in Live!

Get 1:1 Help Now