为什么这段代码在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/