Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class A {
- public:
- virtual void pr() {cout << "A";}
- };
- class B : public A {
- public:
- void pr() override {cout << "B";}
- };
- int main() {
- A *x = new A;
- x->pr();
- B y;
- y.pr();
- x = &y;
- x->pr();
- return 0;
- }
- // OUTPUT: ABB
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement