C++ has this helpful feature that says that the template parameter is implicit in the code inside a template class A
.
However, for construction, this seems to clash with CTAD.
How can I make CTAD take precedence?
For example, here, there is an error in the f
member because A
is interpreted as A<T>
where T
is std::string
, and not deduced from the parameter double
.
#include<string>
template<class T>
struct A {
A(T const& t) {}
auto f() {return A{5.0};} // error here triggered by line 11 `auto a2 = a1.f();`
};
int main() {
A a1{std::string{"hello"}};
auto a2 = a1.f();
}