Frage zur Vererbung
-
Abend,
ich habe folgenden Code:
ref class A { public: virtual void method() { Console::WriteLine("A::method()"); } }; ref class B : public A { public: virtual void method() new { Console::WriteLine("B::method()"); } }; ref class C : public B { public: virtual void method() override { Console::WriteLine("C::method()"); } }; int main(array<System::String ^> ^args) { A^ obj = gcnew C; obj->method(); // Gibt A::method() aus B^ obj2 = gcnew C; obj2->method(); // Gibt C::method() aus
Ich verstehe die Ausgaben nicht ganz. Wieso gibt obj->method() "A::method()" aus? Wie wird da vorgegangen?
Was ich noch weniger verstehe: Wieso gibt obj2->method() "C::method()" aus?