Re: Conversion Operator in Template Class
On Mar 18, 4:12 pm, joec...@gmail.com wrote:
Hmm... Why doesn't this work and use the conversion operator?
(It doesn't compile)
template<typename T>
class Foo
{
};
template<typename T>
void bar(Foo<T>& a){}
template<typename T>
class Goo
{
public:
operator Foo<U>(){return m_foo;}
What's U?
Foo<U> m_foo;
Same question?
};
int main()
{
Goo<float> g;
bar(g); // why doesn't this convert to Foo<U> ??
}
Your class template Goo shouldn't compile, since there is no
symbol U defined anywhere. If you replace the U with T, it
still won't compile, because the compiler doesn't know which
specialization of bar to use, and it can't do overload
resolution before bar has been specialized.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34