是否可以使用std::array<class T, std::size_t N>作为类的私有属性,但在类的构造函数中初始化它的大小?
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?
}
}
Run Code Online (Sandbox Code Playgroud)
我可能会使用指针,但没有它可以这样做吗?