I need to disable the copy assignment operator. This will work:
A& operator=(const A&);
Will it work if I don't specify exact parameters for operator=
?
I mean something like this:
void operator=(void);
The returning value is right, I can write whatever I want, but what about the parameter type?
Will this override the default operator=
for class?
From 12.8p17 of the C++ standard draft:
A user-declared copy assignment operator
X::operator=
is a non-static non-template member function of classX
with exactly one parameter of typeX
,X&
,const X&
,volatile X&
orconst volatile X&
.
I guess this replies better than any other test or sample code.
Note that something similar applies also to the move assignment operator, see 12.8p19:
A user-declared move assignment operator X::operator= is a non-static non-template member function of class X with exactly one parameter of type X&&, const X&&, volatile X&&, or const volatile X&&.
These also confirm that, as you guessed, return value types don't matter.