Got stuck here while going through Bruce Eckel TIC++
Create a class with an assignment operator that has a second argument, a string that has a default value that says “op= call.” Create a function that assigns an object of your class to another one and show that your assignment operator is called correctly.
Is this really possible. Does C++ allow operator=() to have multiple argument?? I tried this:
class X{
public:
X& operator=(const X& x,string val="op=call"){ //! error
}
};
int main(){
X x1;
X x2;
x2=x1;
}
Error given by compiler:
[Error] 'X& X::operator=(const X&, std::string)' must take exactly one argument
I think this is not a valid question or if it is then how to provide multiple argument to assignment operator??
Aucun commentaire:
Enregistrer un commentaire