typedef struct Role {
char* Name;
int Hp;
int MaxHp;
int Mp;
int maxMp;
int lv;
}*PROLE,ROLE;
1. 返回结构体
性能折损很大
Role CreateMonster(const char* name, int hp, int mp) {
Role re {name, hp, hp, mp, mp};
return rt;
}
2. 返回指针
不能返回局部变量的指针
PROLE CreateMonster(const char* name, int hp, int mp) {
// 不能返回局部变量的指针
// Role re {name, hp, hp, mp, mp};
// return rt;
PROLE re = new Role {name, hp, hp, mp, mp};
return rt;
}
3. 返回引用
Role& CreateMonster(const char* name, int hp, int mp) {
PROLE re = new ROLE{ cstr(str),Hp,Hp,Mp,Mp,1 };
return *re;
}
ROLE& role = CreatMonster("aoteman", 1500, 1500);