0

相关代码:

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

4

1 回答 1

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现有名称的名称。

于 2012-04-27T15:28:12.783 回答