What's the best way to create a n array of classes?

closed account (Ey80oG1T)
So I have two classes, A and B. And I want to create an array of A in B. What's the best way to do this?

Should I just create an array normally like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class A
{
private:
  int x, y;

public:
  void DoSomething();
};

class B
{
private:
  vector<A> arr;
};


Or could I have a nested class like so:

1
2
3
4
5
6
7
class B
{
private:
  class A {};

  vector<A> arr;
};


Or perhaps some other method? Thanks.
Who cares? Yes indeed, who needs to know about A?

If the answer is "nobody, but B", then you could go one step further and use pimpl idiom. See https://en.cppreference.com/w/cpp/language/pimpl
Topic archived. No new replies allowed.