Question: how to access the fields of the structure?

class A { private: struct B { std::string W; }; BD[100]; public: A(){}; void addW(std::string W); }; 

Closed due to the fact that the essence of the issue is not clear to the participants of Abyx , VenZell , insolor , aleksandr barakin , user194374 Mar 29 '16 at 6:06 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Explain the question in more detail, what is the problem? - Cerbo
  • Somewhere inside addW D[index].W = W; . The abundance of upper case is confusing. - KoVadim

2 answers 2

For example:

 class A { private: struct B { std::string W; }; BD[100]; int last = 0; public: A(){}; void addW(std::string W) { if (last == 100) throw exception("Выход за пределы диапазона") D[last++].W = W; } }; 

Inside a class, you can do whatever you want with private . If the question of how to address it from the outside is, for example, like this:

 public: A(){}; void addW(std::string W) { D[last++].W = W; } std::string get(int index) const { // Проверка индекса на корректность return D[index].W; } 

    Maybe you should consider using the std::vector container?

     #include <vector> class A { private: struct structB { std::string field; }; std::vector<structB> arrayOfB; public: A() {}; void addString(const std::string& str) { structB appenededB; appendedB.field = str; arrayOfB.push_back(appendedB); } };