3
我始終知道,在C++中,只能使用具有引用或指針的forward聲明類。爲什麼如果我使用下面的forward聲明類作爲模板參數std::vector
我在編譯期間沒有任何問題?將類聲明爲模板參數
感謝
AFG
// MyFile.hpp
class OutClass{
public:
class InnClass;
OutClass();
void print();
// why this doesn't create compile time
std::vector<InnClass> m_data;
};
// MyFile.cpp
class OutClass::InnClass{
public:
InnClass() : m_ciao(0) {}
int m_data;
};
OutClass::OutClass()
: m_data(){
InnClass a, b;
a.m_ciao=1; b.m_ciao=2;
m_data.push_back(a);
m_data.push_back(b);
}
void OutClass::print(){
std::cout << m_data[0].m_ciao << std::endl;
std::cout << m_data[1].m_ciao << std::endl;
}
int main(int argc, char** argv){
OutClass outObj;
outObj.print();
return 0;
}
什麼是您的編譯器和平臺? –
我正在使用g ++/Linux –