gcc:模板参数数量错误

时间:2014-04-21 15:56:39

标签: 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'

我不清楚编译器的实际含义是什么&#34;错误的模板参数数量&#34;?

1 个答案:

答案 0 :(得分:1)

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