Skip to content

Instantly share code, notes, and snippets.

@dschwen
Last active August 29, 2015 14:22
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 dschwen/537915784f12bf8d7f67 to your computer and use it in GitHub Desktop.
Save dschwen/537915784f12bf8d7f67 to your computer and use it in GitHub Desktop.
Copy constructor shenanigans
#include <iostream>
class Base {
public:
Base() {}
Base(const Base & a) {
std::cout << "In Base\n";
}
};
class Alfred : public Base {
public:
Alfred() : Base() {}
Alfred(const Base & a) {
std::cout << "In Alfred(Base)\n";
}
Alfred(const Alfred & a) {
std::cout << "In Alfred(Alfred)\n";
}
};
class Zoe : public Base {
public:
Zoe() : Base() {}
Zoe(const Zoe & a) {
std::cout << "In Zoe(Zoe)\n";
}
};
void test(const Base & base)
{
Base bill(base);
// Alfred aligator(base);
// Zoe zeothrope(base);
}
int main()
{
Base base;
Alfred alfred;
Zoe zoe;
test(base);
test(alfred);
test(zoe);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment