c++ - gcc: 错误的模板参数数量

标签 c++ gcc

为什么这段代码在VS13编译成功,用gcc编译失败?

/////    file my_map.h /////

namespace my 
{
    // my custom map
    template<typename K, typename V, typename order = less<K>, typename allocator = cached_alloc<page_allocator<pair<K,V> > > >
    class map : public set_base<pair<K, V>, K, select1st, order, ins_unique, allocator>
    {
        ...
    };
}

/////    file test.h /////

#include "my_map.h"

template <typename T>    
class Base
{
protected:
    typedef my::map<T, double> MyMap;
    MyMap m_map;                                // this is line NN

public:
    void func(const T& key)
    {
        typename MyMap::iterator it = m_map.find(key);
        if(it != m_map.end()) {
            // ....
        }
    }
};

class Inherited1 : public Base <char>
{ };
class Inherited2 : public Base <int>
{ };

它导致以下错误(gcc 4.1.2)

filepath.h:LineNN error: wrong number of template arguments (1, should be 4)
..: error: provided for 'template<class K, class V, class order, class allocator> class my::map'

我不清楚编译器所说的“错误数量的模板参数”到底是什么意思?

最佳答案

您使用的编译器太旧。 Gcc 4.1.2 于七年前发布。就像那个时代的旧 VC 编译器一样,它有错误。很难找到问题,因为新的编译器工作正常。尝试更新您的编译器。

关于c++ - gcc: 错误的模板参数数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23200876/

相关文章:

c - 生成带有前缀的宏的宏函数(避免字符串化)

c++ - std::function of a value templated method 使用 clang 和 g++ 编译,但不使用 msvc

macos - 未链接的 clang - 编译器错误 (MacOS)

c++ - 返回 PVOID 的模板函数

c++ - c++如何处理ifstream和char数组的 ">>"操作?

c++ - 我如何简单地读取控制台输出

c++ - 为什么operator <<无法成功工作?

c - 特殊字 rune 字

c++ - 如何在二进制文件中设置内置版本号?

c++ - 工厂模式的 API 设计缺陷