Topic: Operator + templates
Author: Jaroslaw Jasinski <jja@askom.com.pl>
Date: 1996/11/26 Raw View
I have a problem with template function operator +
(compiler: Borland C++ 5.0):
Declarations:
template <class A>
class E
{ ... };
class I
{ ... };
Two function templates:
template class <class A, class B>
'some complicated type' operator + (A &a, E<B> &b) // template 1
{ ... }
template class <class A, class B>
'some complicated type' operator + (E<A> &a, B &b) // template 2
{ ... }
I can add:
E<I> i;
'lvalue1' = 1 + i; // ok, template 1 used; number 1 is an
example, // it can be any type
'lvalue2' = i + 1; // ok, template 2 used
but when I try to add third function template
template class <class A, class B>
'some complicated type' operator + (E<A> &a, E<B> &b) // template 3
{ ... }
and add somethig like this:
'lvalue3' = i + i; // error
there is ambiguity between templates 1 and 3.
I think that template 3 could be some (partial?) specjalization of
tempalte 1 but how can it be expressed?
Can commpiler supporting partial specjalization of templates
compile something equivalent?
Jarek
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]