Advertisement
Josif_tepe

Untitled

Dec 28th, 2023
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class base {
  5. public:
  6.      virtual void print() {
  7.         cout << "base class" << endl;
  8.     }
  9.     base() {
  10.        
  11.     }
  12. };
  13. class derived : public base {
  14. public:
  15.    
  16.     void print() override {
  17.         cout << "derived class" << endl;
  18.     }
  19.     derived() : base() {
  20.        
  21.     }
  22. };
  23. int main() {
  24.     base * a = new derived();
  25.     a -> print();
  26.    
  27.    return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement