我的 code :
#include <iostream>
enum EnvelopeMultiPointsType {
ENVELOPE_MULTI_POINTS_TYPE_NORMAL = 0,
ENVELOPE_MULTI_POINTS_TYPE_KICK_PITCH,
kNumEnvelopeMultiPointsTypes
};
class EnvelopeMultiPoints
{
public:
EnvelopeMultiPoints(EnvelopeMultiPointsType type) : mType(type) {
std::cout << mType << std::endl;
}
~EnvelopeMultiPoints() { };
private:
EnvelopeMultiPointsType mType;
};
class Test
{
public:
Test() { };
~Test() { };
private:
EnvelopeMultiPoints mEnv(EnvelopeMultiPointsType::ENVELOPE_MULTI_POINTS_TYPE_NORMAL);
};
int main()
{
Test test;
}
看来我不能用那个枚举来初始化一个类。不知道为什么。我在这里错过了什么?
在线编译器说“EnvelopeMultiPointsType”中没有名为“ENVELOPE_MULTI_POINTS_TYPE_NORMAL”的类型,但它已在上面声明。
最佳答案
这一行
EnvelopeMultiPoints mEnv(EnvelopeMultiPointsType::ENVELOPE_MULTI_POINTS_TYPE_NORMAL);
被解析为函数 mEnv
的声明,该函数返回 EnvelopeMultiPoints
并采用 1 个不存在的 EnvelopeMultiPointsType::ENVELOPE_MULTI_POINTS_TYPE_NORMAL
类型的变量作为一个未命名的参数。
改为像这样初始化您的变量:
EnvelopeMultiPoints mEnv = EnvelopeMultiPointsType::ENVELOPE_MULTI_POINTS_TYPE_NORMAL;
关于c++ - 将此枚举传递给 CTOR 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228966/