| | |
Problem on Returning Reference to Template Object
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
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
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.
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
C++ Syntax (Toggle Plain Text)
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.
KSG
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.
C++ Syntax (Toggle Plain Text)
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 (); } }
Last edited by selvaganapathy; Feb 24th, 2009 at 9:51 am.
KSG
![]() |
Similar Threads
- memory management in wndows 2000 (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Project compiles fine in Windows, but gives undefined references in Linux?? Huh?
- Next Thread: socket c++
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






