W
werasm
Hi All,
I have this example that attempts to call a member template
constructor
whilst explicitly specifying the template parameters. I realize that
by using
static_cast one can force the parameters to the right type (via
argument
deduction), but for normal member templates one [can] explicitly
specify
the template parameters. I would think there would be consistency
here.
Example:
struct X
{
template <class T>
X( T* p );
template <class T>
X foo( T* p );
};
struct Base{};
struct Derived : Base{};
void foo( const X& );
int main()
{
Derived d;
//X x<Base>( &d ); //Does not compile!!!!
X x( static_cast<Base*>(&d) );
foo( x.foo( &d ) );
foo( x.foo<Base>( &d ) ); //Does compile!!!
}
Any comments as to why this is so appreciated, Thanks.
Werner
I have this example that attempts to call a member template
constructor
whilst explicitly specifying the template parameters. I realize that
by using
static_cast one can force the parameters to the right type (via
argument
deduction), but for normal member templates one [can] explicitly
specify
the template parameters. I would think there would be consistency
here.
Example:
struct X
{
template <class T>
X( T* p );
template <class T>
X foo( T* p );
};
struct Base{};
struct Derived : Base{};
void foo( const X& );
int main()
{
Derived d;
//X x<Base>( &d ); //Does not compile!!!!
X x( static_cast<Base*>(&d) );
foo( x.foo( &d ) );
foo( x.foo<Base>( &d ) ); //Does compile!!!
}
Any comments as to why this is so appreciated, Thanks.
Werner