Hi all.
A have two classes: STowar and CTowar-internal.
The goal is to assign a STowar object to CTowar_internal object like this:
CTowar_interanl twi;
STowar t;
...
//filling t object
...
twi = t; // [1]
Here [1] I want to assign. But the problem is, I can't touch the CTowar_internal class to make a new assignment operator, I can only modify the STowar class.
So, I made in STowar a assignment operator:
CTowar_internal& operator=(STowar& tw)
{
CTowar_internal* ret = new CTowar_internal();
ret->KK = "asdf";
return *ret;
}
But it doesn't work. It compiles properly, but the assignment doesnt work. twi object doesn't contain the "asdf" string. Of course, later i will do in the operator body a lot of staff, now it's only "asdf" assignment for testing.
Is this possible to do this by above operator ?
{
CTowar_internal* ret = new CTowar_internal(); //memory leak once the operator returns
ret->KK = "asdf";
return *ret;
}
I don't understand your not having access to the internals, do you mean logically or physically (or you have been instructed not to change the code for that class)?
Does STowar contain a CTowar-internal?
If this is the case why not just add a function, name it whatever you want. Assuming Ctowar-internal has an operator= where Ctowar-internal = Ctowar-internal then: