【发布时间】:2011-01-03 04:01:42
【问题描述】:
我想使用 boost::array 作为类成员,但我不知道编译时的大小。 我想过这样的事情,但它不起作用:
int main() {
boost::array<int, 4> array = {{1,2,3,4}};
MyClass obj(array);
}
class MyClass {
private:
boost::array<int, std::size_t> array;
public:
template<std::size_t N> MyClass(boost::array<int, N> array)
: array(array) {};
};
编译器 gcc 说:
error: type/value mismatch at argument 2 in template parameter list for
‘template<class _Tp, long unsigned int _Nm> struct boost::array’
error: expected a constant of type ‘long unsigned int’, got ‘size_t’
这显然意味着不能使用可变大小的数组作为类成员。如果是这样,这将否定 boost::array 相对于向量或标准数组的所有优势。
你能告诉我我做错了什么吗?
【问题讨论】:
标签: c++ arrays class boost templates