struct Foo
{
template <int bar> Foo()
{}
};
Foo baz<42>(); // TODO: Make this syntactically correct.
Templated Constructor
This isn't extremely important, but for future reference, how might I choose template parameters for a constructor?
Example:
I don't think you can. Since you don't explicitly call the constructor, there is no way to specify the template parameters. This works though:
struct Foo { template < typename T > Foo( T x ) : bar( x ) {} int bar; }; Foo baz( 42.5 );
Quote:Original post by smart_idiot
This isn't extremely important, but for future reference, how might I choose template parameters for a constructor?
The template argument has to be able to be deduced by the constructor arguments. You can do:
template< typename Type >struct dummy {};class your_type{public: template< typename Type > your_type( dummy< Type > ) {}};int main(){ your_type your_object( dummy< int >() );}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement