Last active
August 29, 2015 14:22
-
-
Save dschwen/537915784f12bf8d7f67 to your computer and use it in GitHub Desktop.
Copy constructor shenanigans
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 <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