我正在尝试使用boost multi_array,它在我的主驱动程序代码中有效,但当我尝试在我的头文件中使用它时,它会给我以下错误:
error: no type named 'extents' in namespace 'boost'
main.cpp
#include <boost/multi_array.hpp>
int main()
{
boost::multi_array<double, 3> A(boost::extents[2][2][2]);
return 0;
}
以下作品
c++ -I /usr/local/include/ main.cpp
./a.out
但是,使用头文件则不然。
my_header.hpp
#include <boost/multi_array.hpp>
my_class
{
private:
boost::multi_array<double, 3> A(boost::extents[2][2][2]);
public:
my_class();
};
my_header.cpp
#include "my_header.hpp"
#include <iostream>
my_class::my_class()
{
std::cout << "Test" << std::endl;
}
即
c++ -I /usr/local/include/ -c my_header.cpp
给出:
./my_header.hpp:6:42: error: no type named 'extents' in namespace 'boost'
错误消息令人困惑,但实际上您的语法不正确。试试这个
class my_class
{
private:
boost::multi_array<double, 3> A;
public:
my_class() : A(boost::extents[2][2][2]) {}
};