Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using std::cout;
- using std::endl;
- using std::string;
- class Ancestor
- {
- public:
- Ancestor(): var("ancestor")
- {
- }
- protected:
- string var;
- };
- class Child1 : public Ancestor
- {
- public:
- Child1()
- {
- this->var="child1";
- }
- };
- class Child2 : public Ancestor
- {
- public:
- void output(Ancestor &subject)
- {
- cout << subject.var << endl;
- }
- };
- int main()
- {
- Child1 child1;
- Child2 child2;
- child2.output(child1);
- return 0;
- }
- //$ g++ one1.cpp
- //one1.cpp: В функции-члене ‘void Child2::output(Ancestor&)’:
- //one1.cpp:14:10: ошибка: ‘std::string Ancestor::var’ is protected
Advertisement
Add Comment
Please, Sign In to add comment