Skip to content

Instantly share code, notes, and snippets.

@kgbook
Last active November 28, 2018 04:25
Show Gist options
  • Save kgbook/62c5caa7aa6da93656276b7ffb785284 to your computer and use it in GitHub Desktop.
Save kgbook/62c5caa7aa6da93656276b7ffb785284 to your computer and use it in GitHub Desktop.
[inheritance example]inheritance #inheritance #C++
#include <iostream>
//using namespace std::cout;
class Subject
{
public:
Subject() {
std::cout <<__func__ <<"@LINE#" <<__LINE__ <<std::endl;
}
virtual ~Subject() {
std::cout <<__func__ <<"@LINE#" <<__LINE__ <<std::endl;
}
virtual void doSth() = 0;
};
class ClimateSubject : public Subject
{
public:
ClimateSubject() {
std::cout <<__func__ <<"@LINE#" <<__LINE__ <<std::endl;
}
~ClimateSubject() {
std::cout <<__func__ <<"@LINE#" <<__LINE__ <<std::endl;
}
void doSth() {
std::cout <<__func__ <<"@LINE#" <<__LINE__ <<std::endl;
}
};
int main() {
ClimateSubject p;
p.doSth();
}
// Subject@LINE#9
// ClimateSubject@LINE#23
// doSth@LINE#31
// ~ClimateSubject@LINE#27
// ~Subject@LINE#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment