Template Overloading of Non-Mrember Operator [modified]
-
I am trying to overload an assignment operator that that assigns an underlying type with the the assignment operator of the template's underlying class. It should be much simpler than creating the syntax of my opening sentence. If anyone can tell me what the hell im doing wrong I would be much obliged. template T& operator=(T& t,const Object& object); template class Object{ friend T& operator=(T& t,const Object& object); public: Object(); //ommitted for brevity protected: Object* m_daddy; T m_data; }; //----------------------------------FOLLOWING IS THE CPP FILE #include "StdAfx.h" #include ".\table.h" template T& operator=(T& t,const Object& object){ t = object.m_data; return t; } template Object::Object(){ //the constructor stuff goes here } I GET THE FOLLOWING ERROR c:\Visual Studio Projects\Statistician Pro\Table.h(5): error C2801: 'operator =' must be a non-static member
-
I am trying to overload an assignment operator that that assigns an underlying type with the the assignment operator of the template's underlying class. It should be much simpler than creating the syntax of my opening sentence. If anyone can tell me what the hell im doing wrong I would be much obliged. template T& operator=(T& t,const Object& object); template class Object{ friend T& operator=(T& t,const Object& object); public: Object(); //ommitted for brevity protected: Object* m_daddy; T m_data; }; //----------------------------------FOLLOWING IS THE CPP FILE #include "StdAfx.h" #include ".\table.h" template T& operator=(T& t,const Object& object){ t = object.m_data; return t; } template Object::Object(){ //the constructor stuff goes here } I GET THE FOLLOWING ERROR c:\Visual Studio Projects\Statistician Pro\Table.h(5): error C2801: 'operator =' must be a non-static member
Read your error message.
operator=
must be a member of the class, in this caseObject
.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ