There is no assignment operator invoked at all in this. A a = b;
always invokes a constructor. If b
is of object of type A
, copy-constructor invoked. If b
is object of some other type B
, then suitable constructor invoked, such as A( const B& )
. In any circumstances, A a(b);
and A a = b;
will result in absolutely the same code with the same constructor called once.
The following will NOT compile, since there is no suitable constructor, even though there is suitable assignment operator and default constructor for class TB
:
#include <iostream>
class TA
{
public:
TA()
{
std::cout << "TA()" << std::endl;
}
TA( const TA& )
{
std::cout << "TA(const TA&)" << std::endl;
}
};
class TB
{
public:
TB()
{
std::cout << "TB()" << std::endl;
}
TB( const TB& )
{
std::cout << "TB(const TB&)" << std::endl;
}
TB& operator=( const TA& )
{
std::cout << "TB& operator=( const TA& )" << std::endl;
return ( *this );
}
};
int main( void )
{
TA la;
TB lb = la;
return ( 0 );
}
So the answer to your question is "No, it's not faster, it's 100% the same".