c++ operator must be non static member function [duplicate]
Possible Duplicate:
What does “operator = must be a non-static member” mean? (C++)
I'm trying to write an operator= method as a non member, with 2 arguments like this:
template<class T>
T operator=(T & t, const myclass<T>& m)
{
t = m.val;
re开发者_如何学Cturn t;
}
But I get the error that operator= must be a nonstatic member. Is there a compiler flag or some way to trick the compiler to let me run this?
Thanks
No there is not, this is mandated by the standard, paragraph 13.5.3.1:
An assignment operator shall be implemented by a non-static member function with exactly one parameter.
There isn't, assignment operators need to be declared as members (The rationale is, iirc, to keep you from overriding assignment for primitive or library types).
精彩评论