Dave Theese wrote in news:vn************@news.supernews.com:
Each member of the pair has to, in turn, undergo an implicit
conversion. Specifically int to foo<1> and int to foo<2>. How is it
that this is working (VC++ 6.0 and g++)? My constructor in foo that
takes an int is explicit!!! Can anyone shed light on how this
compiles and runs as if the constructor were not explicit?
Because the template constructor initializes explicitly
i.e:
#include <iostream>
struct X
{
int x;
explicit X( int xx ) : x( xx )
{
std::cerr << "explicit X::X\n";
}
};
template < typename F >
struct single
{
F only;
single( F const &rhs ) : only( rhs ) {}
template < typename U >
single( single< U > const &rhs ) : only( rhs.only )
{
std::cerr << "template single::single\n";
}
};
int main()
{
single< int > si( 1 );
std::cerr << "X ...\n";
single< X > sx( si );
}
Note the line: single( single< U > const &rhs ) : only( rhs.only )
and especialy the only( rhs.only ) whitch is the explicit
initialization.
HTH
Rob.
--
http://www.victim-prime.dsl.pipex.com/