Hi,
I am using VC++6, MFC Application

I am having the member variable - CArray < Coordinates, Coordinates & > mCoordinates. Coordinates is a structure, contains x, y, and z. When i return reference to this object, there is no problem. but When i assign to some reference i get problem.

The Code is

struct Coordinates{
  int x, y, z;
};
class A{
   private:
   CArray < Coordinates, Coordinates & > mCoordinates
   public: CArray < Coordinates, Coordinates & > & GetCoordinates() {
         return mCoordinates;
   }
};

class B {
  public:
     void Print () {
          A objA;
          CArray < Coordinates, Coordinates & >  &ref = objA.GetCoordinates (); 
     }
}

In Class B's Print () function, i am getting problem when assign the coordinates. Compiler says different level of indirection. Anyone suggest me how to solve this.

Recommended Answers

All 2 Replies

change the reference to a pointer and see if that solves the problem.

I changed the reference as pointer that also not working. Finally i found the solution. I just inherit a class from CArray <>, that solves the problem.

struct Coordinates{
  int x, y, z;
};
class CoordinateArray : public CArray < Coordinates, Coordinates & > {};
class A{
   private:
   CoordinateArray mCoordinates
   public: CoordinateArray & GetCoordinates() {
         return mCoordinates;
   }
};

class B {
  public:
     void Print () {
          A objA;
          CoordinateArray  &ref = objA.GetCoordinates (); 
     }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.