C++:数字常量之前的预期标识符
我正在尝试使用 MTL 编写一个小程序,但是当我尝试使 MTL 矩阵成为类的成员时,我收到了上述错误。
#include <boost/numeric/mtl/mtl.hpp>
class myClass
{
private:
mtl::dense2D<double> Ke(6,6);
};
但是,在 main() 中使用相同的语句没有问题:
#include <boost/numeric/mtl/mtl.hpp>
int main(int argc, char** argv)
{
mtl::dense2D<double> Ke(6,6);
return 0;
}
我对 C++ 很陌生,我不认为这与 MTL 真正相关,但这就是我发生错误的地方。
I'm trying to write a small program using MTL, but I'm getting the mentioned error when I try to make a MTL Matrix a member of a class.
#include <boost/numeric/mtl/mtl.hpp>
class myClass
{
private:
mtl::dense2D<double> Ke(6,6);
};
However, there is no problem with the same statement in main():
#include <boost/numeric/mtl/mtl.hpp>
int main(int argc, char** argv)
{
mtl::dense2D<double> Ke(6,6);
return 0;
}
I'm very new to C++, and I don't think this is really related to the MTL, but that's where the error occurred for me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要在构造函数的初始化列表中执行此操作。
You need to do that in the constructor's initialiser list.
因为当你声明时,
你只需要声明它,而不是创建它。这是 C++ 中构造函数的工作:
Because when you declare
you're only supposed to declare it, not create it yet. This is the constructor's job in C++:
您无法在类范围内初始化变量,您需要在构造函数中进行初始化。改变这个:
到这个--
You can't initialize variable within the class scope, you need to do it in a constructor. Change this:
to this --