c++中结构体里面函数的实现
#include<iostream> using namespace std; struct MM { char name[20]; int age; void print() { cout << name << "\t" << age<<endl; } void printdata(); }; void MM::printdata() { cout << name << "\t" << age << endl; } int main() { MM mm={ "哈哈",20 }; MM baby= { "baby", 18 }; mm.print(); MM *pmm = &mm; pmm->print(); baby.printdata(); MM *pbaby = &baby; pbaby->printdata(); while (1); return 0; }
#笔经#