I have a problem involving inheritance in C ++, I can not change an attribute of a base class eg:
// classe base class Base { vector(string) Names; //coloquei entre parenteses porque por algum motivo o string desaparece quando coloco da maneira correta public: void Add(string); string Get(int); }; void Base::Add(string name) { this->Names.push_back(name); } string Base::Get(int name_position) { return this->Names[name_position]; } // classe derivada class void Derived : public Base { public: void New(string); }; void Derived::New(string name) { Base::Add(name); }
What I'm doing in main is like this
Base base; Derived derived; derived.New("joao");
cout<<base.Get(0);
Can anyone tell me what I'm doing wrong, I thought it was possible to change the attribute of a base class using the methods of the base class itself.