This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center




7年前关闭。




我有以下代码:
//MyClass.h
class MyClass {
      typedef std::map<std::string, int> OpMap;
      static const OpMap::value_type opMap[OP_COUNT];

    public:
     //methods
};

//MyClass.cpp
const MyClass ::OpMap::value_type opMap[DDG::OP_COUNT] = {
    MyClass ::OpMap::value_type("hello", 42),
         MyClass ::OpMap::value_type("world", 88),
};

上面的代码编译失败。
只有当我使typdef公开时才可以。
你能解释为什么在这种情况下typedef应该公开吗

最佳答案

线

const DDG::OpMap::value_type opMap[DDG::OP_COUNT] = {

应该
const DDG::OpMap::value_type MyClass::opMap[DDG::OP_COUNT] = {

09-26 02:20