[ HB_BHF @ 15.09.2013. 12:12 ] @
Imam sljedeće klase i main: Code (cpp): class X{ int a; public: virtual int getA(){ return this -> a;} virtual void setA(int a){ this -> a = a;} }; Code (cpp): class Y : public X{ int a; public: int getA() { return this -> a;} void setA(int a){ this -> a = a;} }; Code (cpp): #include <iostream> #include "X.h" #include "Y.h" using namespace std; int main() { X *x = new Y(); x -> setA(5); Y *y = (Y*) x; y -> setA(10); cout << x -> getA() << endl; cout << y -> getA() << endl; } Moje pitanje je.. Zbog čega je ispis 10 10? Može li mi neko pojasniti šta ustvari znači ovo X *x = new Y(); i Y *y = (Y*) x; |