c++ - "Eclipse IDE"中的模板函数无法编译

标签 c++ eclipse visual-studio-2010 templates

我有这样的功能:

template<template <class _Ty, class _A = allocator<_Ty> > class Container>
    static void FreeAttributesVS(const Container<int>& arra)
    {
        for(Container<int>::const_iterator iter = arra.begin();
            iter != arra.end(); ++iter)
        {
            //do smthng
        }
    }

它在 VisualStudio 中编译,但在 Eclipse 中编译器提示 "Invalid template argumetns",我该怎么办?

最佳答案

你需要typename之前 Container<int>::const_iterator因为这是一个依赖类型:

static void FreeAttributesVS(const Container<int>& arra)
{
    for (typename Container<int>::const_iterator iter = arra.begin(); ...)
    //   ^^^^^^^

}

关于c++ - "Eclipse IDE"中的模板函数无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15765670/

相关文章:

c# - Visual Studio 2010 "System.Web"引用未解决 [C#]

c# - 带有动态下拉菜单的 MVC 3 编辑器模板

c# - ReSharper 5 禁用解析 View

c++ - 如何通过调整窗口大小来扩展小部件?

C++ 模板检查类型并使用一些特定的函数

eclipse - Intellij IDEA : Make refactor > Rename not select the whole word

java - 未找到 ID 为 'jacoco' 的插件 + Gradle

c++ - 动态初始化对象

c++ - 具有体面的 C++ FFI 的可破解方案实现

java - 用于项目依赖性的Gradle设置