| | |
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 binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






