Hands-On High Performance Programming with Qt 5
上QQ阅读APP看书,第一时间看更新

Conversions

Another context where temporaries could arise was in the case of constant reference parameters in function calls. As such, references would be allowed to bind to a temporary object and implicit conversion could be triggered, creating a temporary only used inside of the function:

struct T 
{
T(int i) { ... }
};

void func(const T& o);

main()
{
func(1); // creates temporary object T!
}

For that reason, the explicit annotation for constructors was introduced, which blocks such unwanted implicit conversions.