jeudi 28 juillet 2016

C++ an array of objects instantiation (I'm trying to find a compile time solution)

For example, I have the following C++ class:

struct A {
  A(const int value) {}
};

If I want a single object, I can do this:

A a = A(3);

I would like to construct 10 of these objects, I don't know how to instantiate statically.

A a[10]; // This won't compile, as struct A constructor needs an argument 

I can use a pointer A *a, and then create the object one by one, but I am not sure if there is new feature in C++11 available which allows I can do these in 1 shot statically?

Aucun commentaire:

Enregistrer un commentaire