On Aug 14, 2:21 pm, "Alf P. Steinbach" <al...@start.no> wrote:
> * Ed:
> > template <typename P>
> > void Hello(Vector<P> v)
> > {
> > };
> > // use of the template
> > int main()
> > {
> > Hello(1.0f); //Not work
> > float f;
> > Hello(f); //Not work
> > return 0;
> > }
> > I want compiler to understand Hello(1.0f) is
> > Hello( Vector<float>(1.0f) ).
> > But compiler can't find this.
Understandably. A float is not a vector.
> > How can I make implicit constructor of Vector when the
> > argument is float?
> Templated arguments must match *exactly*.
To tell the truth, this has nothing to do with templates. Even
if he had a function "void Hello( Vector<float> v )", it
wouldn't work. (Or maybe it would---he didn't show us the
definition for Vector. But I can't imagine anything called
Vector with a conversion constructor which would take a float.)
--
James Kanze (GABI Software) email:
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
|