2014-04-21 100 views
0

为什么这段代码在VS13中成功编译并且无法通过gcc编译?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' 

目前尚不清楚什么对我的编译器实际上是“错误号码的模板参数”意味着什么?

+4

GCC 4.1.2 ?! olllldddd –

+0

请用'#include's提供一个完整的测试用例。 –

+0

@LightnessRacesinOrbit是的。对不起) –

回答

1

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