c++ - When a compiler can infer a template parameter? -
Sometimes it does not work:
template & lt; Class T & gt; Zero F (tt) {} template & lt; Square T & gt; Classroom Mylals {Public: Mayclass (TT) {}}; Zero test () {f Is there any way to hack around the above example? To wit. Compiler forces the constructor parameter to estimate the template parameters.
Will this be decided in the future, or there is no good reason?
What is the general rule when the compiler can guess the template parameter? Template parameters can be guessed for template templates
Parameter type can be estimated
then it can be estimated:
template & lt; Typename T & gt; Zero F (tt); Template & lt; Typename T & gt; Zero F (standard :: vector v & gt; v); But not here:
template & lt; Typename T & gt; TF () {Return T (); } and class templates not in.
So the general solution to your problem is to create a cover function, similar to standard library function std :: make_pair :
template & lt; Class T & gt; Classes Mylals {Public: Myclass (TT) {} Zero Print () {std :: cout & lt; & Lt; "Try MyClass" & lt; & Lt; Std :: endl; }}; Template & lt; Typename T & gt; MyClass & LT; T & gt; MakeMyClass (tt) {Return MyClass & lt; T & gt; (T); } and then call automatically a = make mail (5); To instantiate the class.
Comments
Post a Comment