Is it not allowed to have several template argumens for assigment operator? [sic]
It's not that it's not allowed, but rather that the compiler has no way to deduce the second argument.
If your function looked something like this:
template<typename T>
bool operator =(T& value)
Then template parameter T
could be deduced: It will be the type of whatever you're trying to set t
to. Since this is all the template parameters, you're good.
However, what happens when you have 2?
template<typename T, typename T2>
bool operator =(T& value)
T
is easily deducible, but what about T2
? How would the compiler know what T2
should be? The answer is it can't.
You do have the option of telling it, by calling the operator function directly:
t.operator=<int, bool>(gg);
But I would imagine that wouldn't be what you want.
Unfortunately for you, the following expression won't work:
t =<bool> gg;
So I think calling operator=()
directly is your only option here.
Imagine that in operator i create object of type T2 and put it some list. I did not show full source code, because problem can be seen from this part
It sounds like you're using the operator=()
for something it wasn't designed to do. operator=()
is really only supposed to be used for copying the other object's state. If everything you need to set your state isn't inherent in the T
, then you probably shouldn't be using operator=()
for this purpose.
Consider splitting it into two separate functions, or move it into a non-operator function altogether. This way, it will be more clear to other people reading your code in the future what it is you're doing anyway.