【问题标题】:GCC compile type error: expected type-specifierGCC 编译类型错误:预期的类型说明符
【发布时间】:2013-10-03 10:45:34
【问题描述】:

我有以下源代码,用 MinGW 编译。但是当我尝试构建时,我遇到了编译类型错误:

main.cpp:11: error: expected type-specifier
   using Iter = MyMap::iterator;
              ^
main.cpp:12: error: expected type-specifier
   using CIter = MyMap::const_iterator;
               ^

GCC 期望在 MyMap 之前有一个说明符。但它期望哪个说明符?

#include <ctime>
#include <map>

template< typename T >
class MyClass
{
private:
    class Inner {};

    using MyMap = std::map< time_t, Inner >;
    using Iter = MyMap::iterator;
    using CIter = MyMap::const_iterator;
};

int main()
{
    return 0;
}

【问题讨论】:

  • 您可能想阅读this old answer
  • 非常感谢。我会仔细阅读的
  • 我的印象是这个问题每天在 SO 上出现好几次。然而,我没能找到一个好的副本。也许这是因为症状可能完全不同(症状就是问题标题的全部内容)?

标签: c++ c++11 compiler-errors


【解决方案1】:

你只需要添加typename:

using Iter = typename MyMap::iterator;

否则编译器不知道::iterator 指的是类型而不是成员变量或方法。

【讨论】:

  • 你可能节省了我几个小时的调试时间!
猜你喜欢
  • 1970-01-01
  • 2012-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多