To tylko jedna z 2 stron tej notatki. Zaloguj się aby zobaczyć ten dokument.
Zobacz
całą notatkę
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)