typedef 一个类型可以同时拥有多个别名:
语法格式:typedef TYPE_NAME, name1, *name2, ...nameN;
#include <iostream> using namespace std; class object { private: float obj_weight; public: void set(float weight); float get(); void msg(); }; void object::set(float weight) { this->obj_weight = weight; } float object::get() { return obj_weight; } void object::msg() { cout << "weight = " << obj_weight << endl; } // 一个类型,可以有好多个别名 typedef object obj, OBJECT, *obj_pt; // test nickname int main(int argc, char** argv) { obj o = obj(); o.set(32.3); o.msg(); obj_pt pt = &o; pt->msg(); OBJECT tmp = OBJECT(); tmp.set(63.3); tmp.msg(); return 0; }