Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class A {
- private:
- int a;
- public:
- A (int _a) {
- a = _a;
- }
- virtual void print() {
- cout << a << endl;
- }
- };
- class B : public A {
- private:
- int b;
- public:
- B(int _a, int _b) : A(_a) {
- b = _b;
- }
- virtual void print() override {
- cout << b << endl;
- }
- };
- int main() {
- A * a = new B(4, 5);
- a->print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment