template instantiation trouble

From: Alexander Stippler (stip_at_mathematik.uni-ulm.de)
Date: 12/31/03


Date: Wed, 31 Dec 2003 14:05:22 +0100

Hello,

I wrote an (templatized) operator==() and don't know why the compiler
doesn't consider it. What prevents it from being chosen?

class Data {};

template <typename D>
class Vector
{
    public:
        typedef Data ConstType;
        typedef Data Type;
};

template <typename D>
bool
operator==(const typename Vector<D>::ConstType &lhs,
           const typename Vector<D>::Type &rhs)
{
    return true;
}

// this operator is chosen, if added.
//bool
//operator==(const Vector<Data>::ConstType &lhs,
// const Vector<Data>::Type &rhs)
//{
// return true;
//}

int
main()
{
    Vector<Data>::ConstType ct;
    Vector<Data>::Type t;

    ct == t;

    return 0;
}

What is not standard conforming, what is not allowed here?

regards,
        alex



Relevant Pages

  • Cannot convert from Type to const Type& error with templates
    ... what other people say before I blame the compiler. ... template<typename F, typename G> ... // Template function to construct compose_t ... // Helper function to form arbitrary predicate ...
    (microsoft.public.vc.language)
  • Re: template copy constructor
    ... This compiler does not consider ... template <typename U> ... as a template copy constructor. ...
    (microsoft.public.vc.language)
  • Re: EVC++: compile errors disappear when preprocessor output is on
    ... template <typename T> ... more elaborate template ... Without seeing actual compiler errors I can only guess. ... be that T hasn't appropriate copy constructor. ...
    (microsoft.public.vc.language)
  • EDG possible sozeof BUG
    ... with CBuilderX and Comeau's online compiler I get: ... template < typename T, typename Type> ... TEST(X, int); ...
    (comp.lang.cpp)
  • Re: msvc++ 2005 template question
    ... the compiler encountered trouble instantiating a template you used on ... dependent name is not a type name. ... do that is by using the 'typename' keyword. ...
    (microsoft.public.vc.language)