小编Den*_*nis的帖子

模板化类中的嵌套结构与std :: map :: const_iterator?

下面的代码在声明迭代器的行生成语法错误:

template <typename T>
class A
{
  public:

    struct B
    {
       int x, y, z;
    };

    void a()
    {
        std::map<int, B>::const_iterator itr; // error: ; expected before itr
    }

    std::vector<T> v;
    std::map<int, B> m;
};
Run Code Online (Sandbox Code Playgroud)

这只有在A是模板化类时才会发生.这段代码出了什么问题?如果我将B移出A,代码编译得很好.

c++ templates nested stdmap

3
推荐指数
1
解决办法
702
查看次数

标签 统计

c++ ×1

nested ×1

stdmap ×1

templates ×1