No deduction in a class template

template<typename T> 
class A { 
  public: 
    A(T b) : a(b) { 
    } 
  private: 
    T a; 
}; 

A object(12); //Why does it give an error?

为什么不能自动从参数12推导出类型T?


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
链接地址: http://www.djcxy.com/p/48398.html

上一篇: 如何让Android应用程序与外部MySQL数据库进行通信

下一篇: 在课堂模板中没有扣除