//auto不能作为数组的类型声明,也不可以用在行参列表中 #include<iostream> #include <string> using namespace std; class human{ private: int m_nSpeed; string m_Name; public: human(string name){ m_Name = name; } void sayhello(){ cout <<"你好!我是"<<m_Name<<endl; } }; int main(){ auto h1 = human("Mike"); //h1的类型可以推到为human的类型 decltype(h1)h2 = human("老刘"); //decltype可以获得某一表达式,函数或数据的数据类型 h1.sayhello(); h2.sayhello(); }
输出:
你好!我是Mike
你好!我是老刘