template<typename T>
class A {
public:
A(T b) : a(b) {
}
private:
T a;
};
A object(12); //Why does it give an error?
Why can't the type T be deduced from the argument 12
automatically?
template<typename T>
class A {
public:
A(T b) : a(b) {
}
private:
T a;
};
A object(12); //Why does it give an error?
Why can't the type T be deduced from the argument 12
automatically?
Template argument deduction applies only to function and member function templates but not to class templates. So your code is ill-formed.
You need to provide the template argument explicitly.
A<int> object(12); //fine