本文包含三个知识点: 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() {
auto a = 1;
auto p = new MM("name", 18);
p->print();
auto func = bind(print, placeholders::_3, placeholders::_1, placeholders::_2);
decltype(a) c;
decltype(p) pp;
pp = new MM("pp", 29);
pp->print();
cout << typeid(pp).name() << endl;
cout << typeid(a).name() << endl;
cout << typeid(func).name() << endl;
}
|