0

I have following inheritance chain:

class Derivation : public std::vector<Symbol> { 
};

class Alternatives : public std::vector<Derivation> { };

class Production : public std::pair<NonTerminal, Alternatives> {
    int order = 0;
};

class Productions : public std::vector<Production> { };

class Grammar {
    
    Productions productions;
    
};

How can I access parent classes to add elements to them?

Or is there maybe even a way to do something like this directly?

productions.production[3].alternatives.push_back(std::vector<Symbol>())

Maybe a little contrived:

productions::parents.last.push_back(std::vector<Symbol()>
von spotz
  • 875
  • 7
  • 17
  • Why do you assume `productions` to have a member `production` if you don't declare it anywhere? It looks like you expect inheritance to magically add members to a class. `Productions` does not _contain_ a vector, it _is_ a vector. [Which is bad design](https://stackoverflow.com/questions/4353203/thou-shalt-not-inherit-from-stdvector). – Lukas-T Nov 22 '20 at 16:11
  • Just a side note: It's rarely a good idea to derive from standard library classes, unless they're explicitely purposed for inheritance. Rather have a private `std::vector` member variable, and expose functions to manipulate it in your class interface. – πάντα ῥεῖ Nov 22 '20 at 16:11
  • Ok, thanks panta rhei. – von spotz Nov 22 '20 at 18:22

0 Answers0