Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 271
  • Last Modified:

How to Nest CArrays in Visual C++.NET

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
MCofer
Asked:
MCofer
  • 2
1 Solution
 
OnegaZhangCommented:
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
 
MCoferAuthor Commented:
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
 
OnegaZhangCommented:
In my project, I would use CArray( ANG1*) since copy a struct is expensive.

Welcome to www.fruitfruit.com
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now