bor_kev said:
Hi,
I had a problem concerning how to overload the operator = in Microsoft
Visual C++ 2005 Beta.
I was told to do it this way : static Myclass^ operator=(Myclass^);
However, it doesn't work and here is the error message i get when i
compile:
error C2805 : binary operator= has too few parameters
does anybody know the solution?
At first C++/CLI has not been finished yet, and VC++ is beta, so these
things are expected.
Now what the current C++/CLI draft (1.8) says in "18.7 Static operators"
is that the static operators shall take two arguments, while the
unmanaged ISO C++ operators continue to apply.
As far as I can understand this means:
ref class Myclass
{
public:
static Myclass^ operator=(Myclass ^, Myclass ^) {}
};
int main()
{
Myclass ^p1= gcnew Myclass;
Myclass ^p2= gcnew Myclass;
p1= p2;
}
should compile (but it doesn't).
However you can still use the regular C++ operator definitions (but
these can not be used by other .NET languages):
ref class Myclass
{
public:
Myclass^ operator=(Myclass ^) { return this; }
};
int main()
{
Myclass ^p1= gcnew Myclass;
Myclass ^p2= gcnew Myclass;
p1= p2;
}
The above produces 100% IL code since only managed types are used,
however this operator can not be used by other .NET languages.