#include <iostream>
class A {
public:
virtual void function() { std::cout << "A" << std::endl; }
};
class B : public A {
public:
void function() { std::cout << "B" << std::endl; }
};
class C : public B {
void function() { std::cout << "C" << std::endl; }
};
int main(){
A *obj = new A;
obj->function();
delete obj;
obj = new B;
obj->function();
delete obj;
obj = new C;
obj->function();
delete obj;
return 0;
}
#include <iostream>
class A {
public:
virtual void function() { std::cout << "A" << std::endl; }
};
class B : public A {
public:
void function() { std::cout << "B" << std::endl; }
};
class C : public B {
void function() { std::cout << "C" << std::endl; }
};
int main(){
A *obj = new A;
obj->function();
delete obj;
obj = new B;
obj->function();
delete obj;
obj = new C;
obj->function();
delete obj;
return 0;
}
To copy to clipboard, switch view to plain text mode
Bookmarks