anon enums porting problem

Discussion in 'C++' started by Olaf Petzold, Nov 8, 2005.

  1. Olaf Petzold

    Olaf Petzold Guest

    Hi,

    the following code fragment doesn't compile:

    ----8<------
    #include <iostream>



    template<class T, std::size_t Sz>
    class Vector
    {
    public:
    typedef const T* const_iterator;

    public:

    #if defined(USE_ANONYMOUS_ENUM)
    enum { Size = Sz };
    #else
    static const std::size_t Size = Sz;
    #endif

    public:
    template <class T2> Vector& M_add_eq(const Vector<T2, Size>&);
    };

    template<class T1, std::size_t Sz>
    template <class T2>
    inline Vector<T1, Sz>&
    Vector<T1, Sz>::M_add_eq (const Vector<T2, Size>& rhs) {
    // make something
    return *this;
    }
    ---->8----

    /usr/local/bin/g++ -V3.3 -O -DUSE_ANONYMOUS_ENUM -c compiler.cc
    compiler.cc:26: Fehler: prototype for `Vector<T, Sz>& Vector<T,
    Sz>::M_add_eq(const Vector<T2, Vector<T, Sz>::Size>&)' does not
    match any in
    class `Vector<T, Sz>'
    compiler.cc:20: Fehler: candidate is: template<class T, unsigned int Sz>
    template<class T2> Vector& Vector::M_add_eq(const Vector<T2, Size>&)
    compiler.cc:26: Fehler: template definition of non-template `Vector<T,
    Sz>&
    Vector<T, Sz>::M_add_eq(const Vector<T2, Vector<T, Sz>::Size>&)'

    /usr/local/bin/g++ -V4.0.2 -O -c compiler.cc
    /usr/local/bin/g++ -V4.0.2 -O -DUSE_ANONYMOUS_ENUM -c compiler.cc

    I'm asontished, that g++ 3.x doesn't compiler it, gcc4 and icc does.
    Normally I would expected an anonymous enum error by gcc4. I've seen
    this for some other compile tests some days ago, but not for these
    example above. What's going on here? Some rules here? How can I get
    these working for older compilers?

    Thanks and regards
    Olaf
     
    Olaf Petzold, Nov 8, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. john
    Replies:
    0
    Views:
    440
  2. =?utf-8?b?QXNiasO4cm4gU8OmYsO4?=

    Enums without identifier, enums and typedef

    =?utf-8?b?QXNiasO4cm4gU8OmYsO4?=, Jan 19, 2007, in forum: C Programming
    Replies:
    10
    Views:
    1,173
    Keith Thompson
    Jan 20, 2007
  3. neilmac
    Replies:
    2
    Views:
    660
    mcdjnaja
    Feb 7, 2008
  4. The Owner

    Anon Array

    The Owner, Feb 26, 2009, in forum: Perl
    Replies:
    0
    Views:
    2,644
    The Owner
    Feb 26, 2009
  5. A L
    Replies:
    1
    Views:
    527
    Alf P. Steinbach /Usenet
    Aug 25, 2010
Loading...

Share This Page