Is it possible to use the std::array<class T, std::size_t N> as a private attribute of a class but initialize its size in the constructor of the class?
class Router{
std::array<Port,???> ports; //I dont know how much ports do will this have
public:
Switch(int numberOfPortsOnRouter){
ports=std::array<Port,numberOfPortsOnRouter> ports; //now I know it has "numberOfPortsOnRouter" ports, but howto tell the "ports" variable?
}
}
I might use a pointer, but could this be done without it?
No, the size must be known at compile time. Use
std::vectorinstead.