implicit conversion for template class

Lars Albertsson lalle@sics.se
Thu Sep 3 10:09:00 GMT 1998


According to my understanding of the December draft (14.6.4.3), this
program should be legal.


template < class T > class Foo {
public:
  Foo(int i): i_(i), t_(0) {};

  int i() const { return i_; };

private:
  int i_;
  T t_;
};

template < class T >
Foo<T> max(Foo<T> f, Foo<T> g) 
{
  if (f.i() > g.i())
    return f;
  else
    return g;
}

int 
main(int, char **)
{
  Foo<long> f(3);
  max(f, 5);
  return 0;
}

// EOF

muneca:/ip6/src/test/compiler> /opt/egcs-1.1a/bin/g++ template_conv.cc
template_conv.cc: In function `int main(int, char **)':
template_conv.cc:25: no matching function for call to `max (Foo<long int> &, int)'

This behaviour is experienced on i686-pc-linux-gnu and
hppa1.1-hp-hpux10.20.

/Lalle



More information about the Gcc-bugs mailing list