Created
August 20, 2016 21:31
-
-
Save AALEKH/8a7feef4a6aab65ee93de0da039d452c to your computer and use it in GitHub Desktop.
Simple inheritance example
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 "box.h" | |
| #include <iostream> | |
| #include <string> | |
| #include <vector> | |
| int main(){ | |
| std::vector<int> vec; | |
| vec.push_back(1); | |
| vec.push_back(13); | |
| vec.push_back(15); | |
| std::string abc = "Hello"; | |
| object obj(vec, abc); | |
| box bo(obj); | |
| std::cout << "String is: " << bo.re_string() << 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
| #ifndef BOX_H | |
| #define BOX_H | |
| #include <iostream> | |
| #include <string> | |
| #include <vector> | |
| #include "object.h" | |
| class box: protected object { | |
| public: | |
| box(object objects): object(objects) { | |
| }; | |
| public: | |
| std::string re_string(){ | |
| return object_name_; | |
| } | |
| }; | |
| #endif; |
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
| #ifndef OBJECT_H | |
| #define OBJECT_H | |
| #include <iostream> | |
| #include <string> | |
| #include <vector> | |
| class object { | |
| public: | |
| object(std::vector<int> const& v, std::string const& object_name): v_(v.begin(), v.end()), object_name_(object_name) {} | |
| protected: | |
| std::vector<int> v_; | |
| std::string ; | |
| }; | |
| #endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment