C结构体
struct hero
{
unsignede char name[10];
int height;
float weight;
};
struct hero LuBan;
C++
前面看明白了,这个地方就不多说话!
将结构体定义中的关键字struct换成class,就得到了C++中类的定义。
class Hero //类名习惯首字母大写
{
//属性
unsigned char name[10];
int height;
float weight;
//行为
void eat()
{吃肉!} //仅做说明
void sleep()
{站着睡!}
void KillMonsters()
{使用河豚手雷打怪!}
}; //分号
用类定义的就叫对象。
Hero LuBan; //定义了一个Hero类的对象LuBan