Skip to content

Instantly share code, notes, and snippets.

@AALEKH
Created August 20, 2016 21:31
Show Gist options
  • Select an option

  • Save AALEKH/8a7feef4a6aab65ee93de0da039d452c to your computer and use it in GitHub Desktop.

Select an option

Save AALEKH/8a7feef4a6aab65ee93de0da039d452c to your computer and use it in GitHub Desktop.
Simple inheritance example
#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;
}
#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;
#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