Created
March 29, 2010 22:55
-
-
Save mwbrooks/348520 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> // printf function | |
class SuperClass | |
{ | |
public: | |
SuperClass(int foo) | |
{ | |
printf("SuperClass constructor fired with value %d\n", foo); | |
} | |
}; | |
class SubClass : public SuperClass | |
{ | |
public: | |
// Call the superclass constructor in the subclass initialization list. | |
SubClass(int foo, int bar) : SuperClass(foo) | |
{ | |
printf("SubClass constructor fired with values %d %d\n", foo, bar); | |
} | |
}; | |
int main (int argc, char * const argv[]) { | |
SubClass *subClass = new SubClass(12, 24); | |
// Print: SuperClass constructor fired with value 12! | |
// Print: SubClass constructor fired with values 12 24! | |
delete subClass; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment