Sunday, February 25, 2018

C++ : Polymorphism - Virtual Destructors illustration through program

#include <iostream>
using namespace std;
class B {
public:
    B() { cout << "98 "; }
virtual ~B() { cout << "56 "; } // Don't Edit or Modify the "cout"

}; // End of class B

class D : public B {
    int n;
public:
    D(int p):n(p) { cout << n << " "; }
    ~D() { cout << n*2 << " "; }
}; // End of class D

int main() {
    int n ; cin >> n ;
    B *basePtr = new D(n);
    delete basePtr;
    return 0;
}

No comments:

Post a Comment

Query for finding high dividend paying stocks

 Post the following query in Screen.in, to get list of high dividend yield stocks: Dividend yield > 6 AND Dividend last year > 1000 AN...