我正在使用一些容器。參考矢量存在問題,無法正常檢測。C++ 11如何在向量中使用引用?
error C2039: 'vecMsg' : is not a member of 'std::_Vector_iterator <std::_Vector_val>std::_Simple_types<T2 &>>>'
爲什麼不能識別成員變量?
vector<T1> vec1;
vector<T2> vec2;
vector<T1>::iterater iVec1;
vector<T2>::iterater iVec2;
vector<T2&>::iterater iInVec;
struct T1
{
public:
vector<T2&> inVec;
}
struct T2
{
public:
vector<std::string> vecMsg;
}
輸入vec1.inVec
for(iVec1 = vec1.begin(); iVec1 != vec1.end(); iVec1++)
{
for(iVec2 = vec2.begin(); iVec2 != vec2.end(); iVec2++)
{
// blaa if
iVec1->inVec.push_back(*iVec2);
}
}
訪問vecMsg一些數據vec1.inVec
for(iVec1 = vec1.begin(); iVec1 != vec1.end(); iVec1++)
{
for(iInVec = iVec1->inVec.begin(); iInVec != iVec1->inVec.end(); iInVec++)
{
// Error occurs here.
int nSize = iInVec->vecMsg.size();
}
}
'iterater' ...? :P – cHao
引用的向量不可能。 – deviantfan