I’m trying to do something I’m not entirely sure is even possible. I’m trying to overload an equals operator something like this:
Class A //Defined somewhere
Struct B{
float bobsAge;
};
B& operator=(A,B){
A.GetAge("bob",B.bobsAge);
return B;
}
Function(getAge){
A Names;
B structNames;
structNames = Names;
}
I understand that this might not be possible, as I understand the operator= is used to do things such as setting one object of the same type equal to another object. Or is this possible to do but I’m doing something wrong.
Thanks ahead of time.
What you are trying to do is to overload the assignment operator However, the standard approach would be to provide a conversion constructor:
And then let that implicit conversion kick in for expressions such as
You could have provided an assignment operator
but it seems unintuitive to allow only assignment from
BtoA, and not construction.