将此枚举传递给CTOR有什么问题?

mar*_*zzz 1 c++ enums class init

我的代码:

#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;
}
Run Code Online (Sandbox Code Playgroud)

我似乎无法使用该枚举初始化一个类.不知道为什么.我在这里错过了什么?

在线编译器在'EnvelopeMultiPointsType'中没有提到名为'ENVELOPE_MULTI_POINTS_TYPE_NORMAL'的类型,但它在上面声明.

Sin*_*all 5

这条线

EnvelopeMultiPoints mEnv(EnvelopeMultiPointsType::ENVELOPE_MULTI_POINTS_TYPE_NORMAL);
Run Code Online (Sandbox Code Playgroud)

被解析为函数的声明,该函数mEnv返回EnvelopeMultiPoints并将不存在EnvelopeMultiPointsType::ENVELOPE_MULTI_POINTS_TYPE_NORMAL类型的1个变量作为单个未命名参数.

像这样初始化你的变量:

EnvelopeMultiPoints mEnv = EnvelopeMultiPointsType::ENVELOPE_MULTI_POINTS_TYPE_NORMAL;
Run Code Online (Sandbox Code Playgroud)