There is a class:

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

I need an array of instances of class A. Tell me how to do this?

  • A a[N]; - an array of N elements of type A - αλεχολυτ

1 answer 1

For example,

 A a[20]; 

Or is it not what you want?

If they need to be created at runtime, for example

 A* a = new A[20]; 

The same array of 20 class elements. do not forget to delete them using delete[]a .

If only one -

 A* a = new A; 

It is necessary to delete same delete , but already without parentheses: delete a; .

And - think about applying the vector vector<A> , which will do all the necessary manipulations for you.

  • Already in the running program at the request of the user to create another object. - Luntic
  • @Luntic change the question according to your task. To create an array in runnta there is new A[N] . This is written in any language textbook. - αλεχολυτ