Skip to content

Instantly share code, notes, and snippets.

@mwbrooks
Created March 29, 2010 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwbrooks/348520 to your computer and use it in GitHub Desktop.
Save mwbrooks/348520 to your computer and use it in GitHub Desktop.
#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