我有以下代碼:模板參數
template<typename T, typename Allocator = std::allocator<T> >
class Carray {
// ...
typedef T* pointer;
typedef pointer iterator;
// ...
};
現在我想爲iterator_traits
做局部的專業化。這似乎確定了我,但G ++ 4.4.5抱怨:
#include <iterator>
namespace std {
template<typename T, typename Allocator>
struct iterator_traits<typename Carray<T, Allocator>::iterator> { // line 128
typedef T value_type;
typedef typename Allocator::difference_type difference_type;
typedef typename Allocator::reference reference;
typedef typename Allocator::pointer pointer;
typedef typename std::random_access_iterator_tag iterator_category;
};
}
這是完全錯誤消息:
carray.h:128: error: template parameters not used in partial specialization:
carray.h:128: error: ‘T’
carray.h:130: error: ‘Allocator’ has not been declared
carray.h:131: error: ‘Allocator’ has not been declared
carray.h:132: error: ‘Allocator’ has not been declared
我不能重現這一點。你如何把它們放在一起? – Beta
http://codepad.org/5gVzgYKc在Ubuntu 10.10上使用g ++ 4.4.5進行編譯,完整命令:'g ++ test.cpp' – orlp
您是否在頭文件中定義了'Carray'文件,它專用於'iterator_traits'? – Nawaz