- Hands-On High Performance Programming with Qt 5
- Marek Krajewski
- 83字
- 2021-07-02 13:53:59
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.