模板代码不会与GCC编译

时间:2012-04-27 13:27:40

标签: c++ templates map

相关代码:

Line 476: 
typedef KeyWrapper < Key, gist_traits, KeyAllocator, key_policy > KeyWrapper;

Line 304: 
template<class Key, class GIST_TRAITS, class Allocator, class key_policy >
    struct KeyWrapper : public KeyWrapperImpl<Key, GIST_TRAITS, Allocator, typename         key_policy::type >
    {
        typedef KeyWrapperImpl<Key, GIST_TRAITS, Allocator, typename key_policy::type > base;
        typedef KeyWrapper<Key, GIST_TRAITS, Allocator, key_policy> this_type;
        KeyWrapper() {}
        ~KeyWrapper() {}
        explicit KeyWrapper(const Key& k): base(k) {}
        this_type& operator=(const KeyWithGist<Key, GIST_TRAITS, key_policy>& k)
        {
            base::operator=(k);
            return *this;
        }

    };
Line 477:
typedef KeyWithGist < Key, gist_traits, key_policy > KeyWithGist;


Line 194:
template<class Key, class GIST_TRAITS, class key_policy>
    struct KeyWithGist : public KeyWithGistImpl<Key, GIST_TRAITS, typename key_policy::type>
    {
        typedef KeyWithGistImpl<Key, GIST_TRAITS, typename key_policy::type> base;
        KeyWithGist(const Key& k) : base(k) {}
    };

Line 1307:
typedef iter<value_type> iterator;

Line 731:
typedef iter<value_type> iterator;

Line 1308:
typedef iter<const value_type> const_iterator;

Line 732:
typedef iter<const value_type> const_iterator;

Line 1309:
typedef typename boost::reverse_iterator<iterator> reverse_iterator;

Line 733:
typedef typename boost::reverse_iterator<iterator> reverse_iterator;

Line 1310:
typedef typename boost::reverse_iterator<const_iterator> const_reverse_iterator;

Line 734:
typedef typename boost::reverse_iterator<const_iterator> const_reverse_iterator;

错误:

stree.h|476|error: declaration of ‘typedef struct sti::implementation::KeyWrapper<Key, gist_traits, typename Allocator::rebind<Key>::other, key_policy> sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::KeyWrapper’ [-fpermissive]|

stree.h|304|error: changes meaning of ‘KeyWrapper’ from ‘struct sti::implementation::KeyWrapper<Key, gist_traits, typename Allocator::rebind<Key>::other, key_policy>’ [-fpermissive]|

stree.h|477|error: declaration of ‘typedef struct sti::implementation::KeyWithGist<Key, gist_traits, key_policy> sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::KeyWithGist’ [-fpermissive]|

stree.h|194|error: changes meaning of ‘KeyWithGist’ from ‘struct sti::implementation::KeyWithGist<Key, gist_traits, key_policy>’ [-fpermissive]|

stree.h|1307|error: declaration of ‘typedef class sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iter<ValueType> sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iterator’|

stree.h|731|error: conflicts with previous declaration ‘typedef class sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iter<ValueType> sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iterator’|

stree.h|1308|error: declaration of ‘typedef class sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iter<const ValueType> sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::const_iterator’|

stree.h|732|error: conflicts with previous declaration ‘typedef class sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iter<const ValueType> sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::const_iterator’|

stree.h|1309|error: declaration of ‘typedef class boost::reverse_iterator<sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iter<ValueType> > sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::reverse_iterator’|

stree.h|733|error: conflicts with previous declaration ‘typedef class boost::reverse_iterator<sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iter<ValueType> > sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::reverse_iterator’|

stree.h|1310|error: declaration of ‘typedef class boost::reverse_iterator<sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iter<const ValueType> > sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::const_reverse_iterator’|

stree.h|734|error: conflicts with previous declaration ‘typedef class boost::reverse_iterator<sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::iter<const ValueType> > sti::implementation::stree<Key, ValueType, Allocator, comparator, key_extractor, BN, key_policy, value_policy, gist_traits>::const_reverse_iterator’|

||=== Build finished: 12 errors, 0 warnings ===|

注意: 我试图建立一个发布在codeproject上的地图版本,但似乎它不会与GCC编译。任何人都可以详细说明为什么下面的代码不能在GCC上编译?

http://www.codeproject.com/Articles/27799/Stree-A-fast-std-map-and-std-set-replacement

1 个答案:

答案 0 :(得分:0)

您无法使用typedef重新定义已定义的类型名称。它实际上与模板没有任何关系。以下代码具有相同的问题:

typedef float MyType;
typedef int MyType;

typeToy.cpp:4:13: error: conflicting declaration ‘typedef int MyType’
typeToy.cpp:3:15: error: ‘MyType’ has a previous declaration as ‘typedef float MyType’

typedef目标选择与现有名称不同的名称。