成员对象构造函数和枚举
为什么这不能编译?
File.hpp
class CTest
{
public:
enum enumTest { EN_TEST };
//constructor:
CTest(enumTest f_en);
};
AnotherFile.hpp
#include "File.hpp"
class CAnotherTest
{
public:
CTest obj_Test(CTest::EN_TEST);
};
Visual Studio 说:错误 C2061:语法错误:标识符“EN_TEST”
armcc 编译器说:错误:#757:常量“CTest::EN_TEST”不是类型名称
谢谢,Mirco
Why does this not compile?
File.hpp
class CTest
{
public:
enum enumTest { EN_TEST };
//constructor:
CTest(enumTest f_en);
};
AnotherFile.hpp
#include "File.hpp"
class CAnotherTest
{
public:
CTest obj_Test(CTest::EN_TEST);
};
Visual Studio says: error C2061: syntax error : identifier 'EN_TEST'
armcc compiler says: error: #757: constant "CTest::EN_TEST" is not a type name
Thanks, Mirco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你不能像那样初始化。只能对
static const
整型进行类内初始化。在构造函数中使用初始化列表,如下所示:
You cannot initialize like that. In-class initialization can be done for only
static const
integral type.Use initialization-list in the constructor, as:
因为,
被评估为名为 obj_Test 的函数。现在它应该有一个类型参数,但是,
CTest::EN_TEST
是一个值,而不是类型。如果希望
obj_Test
是一个对象,那么您可以在构造函数中将CTest::EN_TEST
传递给它:Because,
is evaluated as a function named
obj_Test
. Now it should have argument as a type, however,CTest::EN_TEST
is a value, not a type.If it's intended that
obj_Test
an object then you have passCTest::EN_TEST
to it in the constructor:因为您的
CAnotherTest
语法是错误的。也许你的意思是这样的?Because your syntax for
CAnotherTest
is wrong. Perhaps you mean something like this?