简体   繁体   English

gcc:模板参数数量错误

[英]gcc: wrong number of template arguments

Why this code compiles succesfully in VS13 and fails to compile by 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>
{ };

It results in following errors (gcc 4.1.2) 导致以下错误(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'

It is not clear for me what compiler actually means by "wrong number of template arguments "? 对我来说,不清楚“错误的模板参数数量”到底是什么意思?

The compiler you are using is too old. 您使用的编译器太旧了。 Gcc 4.1.2 was released seven years ago. Gcc 4.1.2于七年前发布。 It had bugs just as the old VC compilers of that era. 就像那个时代的旧VC编译器一样,它具有一些错误。 It is hard to find the problem as new compilers work fine. 由于新的编译器工作正常,因此很难找到问题。 Try updating your compiler. 尝试更新您的编译器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM