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 type T be automatically inferred from argument 12 ?
12
The output of the template argument applies only to function and member templates, and not to class templates. Thus, your code is poorly formed.
You need to provide the template argument explicitly.
A<int> object(12); //fine