#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(0);'作爲函數聲明一樣。相反,使用'EnvelopeMultiPoints mEnv(EnvelopeMultiPointsType a_type);' –