Lecture overview -- Keyboard shortcut: 'u'  Previous page: Classes and Conversion -- Keyboard shortcut: 'p'  Next page: Classes and Conversion: Examples -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Help page about these notes  Alphabetic index  Course home  Lecture 3 - Page 19 : 36
Notes about C++
Abstraction Mechanisms, Part 1
Implicit Conversion

Conversion operators TT::operator S() and constructors T::T(S) can be called implicitly

  • Implicit conversions

    • A constructor can be used implicitly, unless it is marked explicit.

    • A conversion operator can be activated implicitly.

  • Too many implicit conversions may easily lead to ambiguities

    • The compiler finds out

    • The programmer will have to resolve such issues.

  • An alternative to conversion operators and implicit use

    • Program an ordinary member function instead of a conversion operator

    • T::make_int(){...}       instead of

    • T::operator int(){...}