C++ Nested classes driving me crazy
问题 i am trying to compile this very simple piece of code class myList { public: std::vector<std::string> vec; class Items { public: void Add(std::string str) { myList::vec.push_back(str); }; }items; }; int main() { myList newList; newList.items.Add("A"); } what can i do to make this work without creating more objects that needed or overcomplicating stuff... 回答1: Add a couple of constructors and a pointer to the parent class. #include <string> #include <vector> class myList { public: std::vector