相关疑难解决方法(0)

在使用它的类的构造函数中初始化std :: array的大小

是否可以使用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)

我可能会使用指针,但没有它可以这样做吗?

c++ arrays templates std c++11

4
推荐指数
2
解决办法
2216
查看次数

标签 统计

arrays ×1

c++ ×1

c++11 ×1

std ×1

templates ×1