O'Reilly logo

Efficient C++ Performance Programming Techniques by David Mayhew, Dov Bulka

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Type Mismatch

The previous example is a special case of the more general type mismatch. We tried to initialize an object of type Rational with an integer. The generic case of type mismatch is any time an object of type X is expected and some other type is provided. The compiler needs, somehow, to convert the provided type into the expected object of type X. A temporary may get generated in the process. Look at the following:

{
    Rational r;
    r = 100;
    ...
}

Our Rational class did not declare an assignment operator that takes an integer parameter. The compiler, then, expects a Rational object on the right-hand side that will be bit-blasted to the left-hand side. The compiler must find a way to convert the integer argument we provided into an object ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required