简体   繁体   中英

Template code wont compile with GCC

Relevant code:

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;

Errors:

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 ===|

Notes: Im trying to build a map version posted on codeproject, but it seems it wont compile with GCC. Can anyone please shed some light on why the following code does not compile on GCC?

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

You can't use typedef to redefine a typename that is already defined. It really doesn't have anything to do with templates. The following code has the same problem:

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’

Choose a different name for your typedef targets than the already existing names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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