www.digitalmars.com         C & C++   DMDScript  

c++ - template conversion operator

template <class T>
struct A
{ };

template<class T>
struct B
{
  B &operator=(const B &b)
  {
    return *this;
  }

  B &operator=(A<T> a)
  {
    return *this;
  }
  
  template<class U>
  operator A<U>()
  // Error: 'B<int >::operator A<int >' is already defined
  {
    return A<U>();
  }
};

int main()
{
  B<int> a;
  a = B<int>();

  return 0;
}


Extracted from STLport's std::auto_ptr - it's quite annoying as there is no
clean workaround...


bye, Christof

-- 
http://cmeerw.org                                 JID: cmeerw jabber.at
mailto cmeerw at web.de

...and what have you contributed to the Net?
Dec 23 2002