See getname.py and try to implement the same in C++ with and without using templates.
Last active
May 21, 2016 07:40
-
-
Save techtonik/ce85e2e5e1773e02f91cb8e1156d049a to your computer and use it in GitHub Desktop.
Driver inheritance pattern - parent should print child's name
This file contains hidden or 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> | |
| #include <string> | |
| class Driver { | |
| public: | |
| std::string name = "Unknown"; | |
| }; | |
| int main() { | |
| Driver d; | |
| std::cout << d.name << std::endl; | |
| } |
This file contains hidden or 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
| """ | |
| This Python code contains two driver classes - parent constructor prints | |
| name of current driver. This is an example that should be ported to C++. | |
| Code is placed into public domain. | |
| """ | |
| class Driver(object): | |
| name = "Unknown" | |
| def __init__(self): | |
| print(self.name) | |
| class SpecificDriver(Driver): | |
| name = "Specific" | |
| def __init__(self): | |
| super(SpecificDriver, self).__init__() | |
| Driver() | |
| SpecificDriver() | |
| """ | |
| This prints two strings to console | |
| Unknown | |
| Specific | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment