Home >Backend Development >C++ >Can a Non-Template Class Have a Parameterless Template Constructor?
Is Template Constructor Without Parameter Possible?
Question:
Can a non-template class have a template constructor with no arguments? Is it true that it conflicts with the default constructor?
Answer:
Explicitly specifying template arguments is not possible when calling a constructor template. They are deduced through argument deduction. Calling Foo
The workaround you suggested still requires an argument passed to call the constructor template. It's unclear what your intended goal is in this scenario.
An alternative is to use a default constructor instead of a template constructor with no arguments. If the non-template class has other constructors, using a default template constructor with empty parentheses () can avoid parameter ambiguity.
The above is the detailed content of Can a Non-Template Class Have a Parameterless Template Constructor?. For more information, please follow other related articles on the PHP Chinese website!