Skip to content

Instantly share code, notes, and snippets.

@j2doll
Created August 12, 2017 08:16
Show Gist options
  • Save j2doll/788476e5da625dfeaa14598244009979 to your computer and use it in GitHub Desktop.
Save j2doll/788476e5da625dfeaa14598244009979 to your computer and use it in GitHub Desktop.
simple overriding example
// overring.cpp
// simple overriding example
#include <iostream>
using namespace std;
class A
{
public:
A() { cout << "A()" << endl; }
~A() { cout << "~A()" << endl; }
};
class B : public A
{
public:
B() { cout << "B()" << endl; }
~B() { cout << "~B()" << endl; }
};
int main(int argc, char *argv[])
{
B b;
// B *pb = new B();
// delete pb;
return 0;
}
// console output:
// A()
// B()
// ~B()
// ~A()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment