#include <string>
#include <map>
namespace myNamespace
{
struct MyStruct
{
static std::map<int, std::string> idNameMap;
// some other static properties
};
class MyClass
{
private:
void myMethod() {
std::map<int, std::string>& myMap = MyStruct::idNameMap; // C2062: type 'int' unexpected
for (auto& it : myMap)
{
// do some stuff with map values
}
}
};
}
我想引用MyStruct
中的靜態映射屬性,但它產生此錯誤。我不確定是否需要更多的上下文,但如果是這樣,請讓我知道。錯誤C2062:鍵入意外時,引用std :: map
你執行#included
@roalz:我確實。將添加到澄清 – sookie
您應該編輯您的問題,以提供一個最小的,完整的和可驗證的示例:http://stackoverflow.com/help/mcve – roalz