本文包含三个知识点:
1:auto的使用
2:decltype的使用
3:typeid的使用 (打印类型的名字)
#include<iostream>
#include<string>
#include<functional>
using namespace std;
class MM {
public:
MM(){}
MM(string name,int age):name(name),age(age){}
void print() {
cout << name << '\t' << age << endl;
}
MM& operator=(const MM& temp) {
this->name = temp.name;
this->age = temp.age;
return *this;
}
private:
string name;
int age;
};
void print(int a, string b, MM c) {
}
string returnString() {
return string("DisAble");
}
int main() {
//1.auto 推断必须存在赋值操作
auto a = 1;
auto p = new MM("name", 18);
p->print();
auto func = bind(print, placeholders::_3, placeholders::_1, placeholders::_2);
//2.decltype(表达式)
decltype(a) c;//decltype(a) 返回一个int
decltype(p) pp;
pp = new MM("pp", 29);
pp->print();
//3.typeid打印类型的名字
cout << typeid(pp).name() << endl;
cout << typeid(a).name() << endl;
cout << typeid(func).name() << endl;
}