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; }
本文由 lnlidawei 原创、整理、转载,本文来自于【博客园】; 整理和转载的文章的版权归属于【原创作者】; 转载或引用时请【保留文章的来源信息】:https://www.cnblogs.com/lnlidawei/p/15678063.html