Conversion operator

Nasza ocena:

3
Wyświetleń: 679
Komentarze: 0
Notatek.pl

Pobierz ten dokument za darmo

Podgląd dokumentu
Conversion operator - strona 1 Conversion operator - strona 2

Fragment notatki:

Conversion operator  a.k.a. conversion function / method,  it converts object of its own class to other class T::operator X();  Conversion operator of class T to the X type: - no return value specified, - no argument(s) specified, - declared as a class method  example: person::operator int();  conversion does not have to be explicit: person o; int i=o+5;  In expressions - for the specific object conversion is performed only if it is necessary - no more than one conversion per single argument - no ambiguity allowed  for example, for classes A, B and C, conversion operators B::operator A() and C::operator B(); are defined int f(A a); A a; B b; C c; f(a); // ok f(b); // f(A(b)) // f(c); // there is no operator C::operator A() // compiler cannot interpret this as f(A(B(c))) // (2 conversions of a single argument - not allowed) ... zobacz całą notatkę



Komentarze użytkowników (0)

Zaloguj się, aby dodać komentarz