C ++:数字常量前的期望标识符 [英] C++: expected identifier before numeric constant
本文介绍了C ++:数字常量前的期望标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图使用MTL编写一个小程序,但是当我尝试使一个MTL Matrix成为一个类的成员时,我收到了提到的错误。
#include< boost / numeric / mtl / mtl.hpp>
class myClass
{
private:
mtl :: dense2D< double> Ke(6,6);
};但是,main()中的同一语句没有问题: $ b
$ b #include< boost / numeric / mtl / mtl.hpp>
int main(int argc,char ** argv)
{
mtl :: dense2D< double> Ke(6,6);
return 0;
}
我是C ++的新手,我不认为这是
解决方案你需要在构造函数的初始化列表中这样做。
class myClass {
mtl :: dense2D< double> Ke;
public:
myClass():Ke(mtl :: dense2D< double>(6,6)){}
};
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.
解决方案 You need to do that in the constructor's initialiser list.
class myClass {
mtl::dense2D<double> Ke;
public:
myClass() : Ke(mtl::dense2D<double>(6, 6)) { }
};
这篇关于C ++:数字常量前的期望标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文