As per cppreference, a copy assignment operator should non templated :
A copy assignment operator of class T is a non-template non-static member function with the name operator= that takes exactly one parameter of type T, T&, const T&, volatile T&, or const volatile T&"
But in this sample program, i wrote a templated assignment operator, there is no compilation issue and it infact is called(and not default implicitly generated).
template<typename T1>
class Sample
{
public:
T1 a;
Sample(T1 b)
{
a=b;
}
template<typename T2>
void operator = (T2& obj2)
{
cout<<"This wont be called";
(*this).a=obj2.a;
}
};
Sample<int> obj1(2);
Sample<int> obj2(3);
obj2=obj1;
Output:
This wont be called
Am i misunderstanding something?