Last active
May 21, 2016 07:40
-
-
Save techtonik/ce85e2e5e1773e02f91cb8e1156d049a to your computer and use it in GitHub Desktop.
Revisions
-
techtonik revised this gist
May 21, 2016 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,8 @@ class Driver { } }; // need public here to inherit init() class SpecificDriver : public Driver { public: std::string name = "Specific"; @@ -20,8 +21,7 @@ int main() { Driver d; SpecificDriver sd; // this gives Unknown Unknown =/ d.init(); sd.init(); } -
techtonik revised this gist
May 21, 2016 . 2 changed files with 10 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,3 +4,7 @@ with and without using templates. $ python getname.py Unknown Specific $ g++ -std=c++14 -O2 -Wall -pedantic main.cpp && ./a.out Unknown Specific 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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ #include <iostream> #include <string> class Driver { public: std::string name = "Unknown"; void init() { std::cout << name << std::endl; } }; class SpecificDriver : Driver { @@ -19,9 +20,8 @@ int main() { Driver d; SpecificDriver sd; // now need to make it a part of parent init() method, // because it won't work in constructor d.init(); std::cout << sd.name << std::endl; } -
techtonik revised this gist
May 21, 2016 . 2 changed files with 18 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,6 @@ See getname.py and try to implement the same in C++ with and without using templates. $ python getname.py Unknown Specific 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ // g++ -std=c++14 -O2 -Wall -pedantic main.cpp && ./a.out #include <iostream> #include <string> @@ -7,8 +9,19 @@ class Driver { }; class SpecificDriver : Driver { public: std::string name = "Specific"; }; int main() { Driver d; SpecificDriver sd; // now need to make it a part of parent // init() method (because it won't work // in constructor) std::cout << d.name << std::endl; std::cout << sd.name << std::endl; } -
techtonik revised this gist
May 21, 2016 . 1 changed file with 6 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ #include <iostream> #include <string> class Driver { @@ -6,5 +7,8 @@ class Driver { }; int main() { Driver d; std::cout << d.name << std::endl; } -
techtonik revised this gist
May 21, 2016 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ #include <string> class Driver { public: std::string name = "Unknown"; }; int main() { } -
techtonik revised this gist
May 20, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ See getname.py and try to implement the same in C++ with and without using templates. -
techtonik created this gist
May 20, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ """ 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 """