fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. class Base{
  6. std::vector<std::string> Names; //coloquei entre parenteses porque por algum motivo o string desaparece quando coloco da maneira correta
  7. public:
  8. void Add(std::string);
  9. std::string Get(int);
  10. };
  11. void Base::Add(std::string name){
  12. this->Names.push_back(name);
  13. }
  14. std::string Base::Get(int name_position){
  15. return this->Names[name_position];
  16. }
  17. // classe derivada
  18. class Derived : public Base{
  19. public:
  20. void New(std::string);
  21. };
  22. void Derived::New(std::string name){
  23. Base::Add(name);
  24. }
  25.  
  26. int main(){
  27. Base base;
  28. Derived derived;
  29. derived.New("joao");
  30. std::cout<<derived.Get(0);
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 4400KB
stdin
Standard input is empty
stdout
joao