1.在实例类Student.h中定义一个自己的方法

public:

int getSno();

2.在实例类Student.cpp中实现这个方法

int Student::getSno()
{
  return sno;
}

3.在游戏场景类HelloWorld.h中声明这个实例类的对象

private:

Student *stu; //注意这里必须是Student类型的才能使用getSno方法,如果是Sprite类型的则会提示没有这个方法

4.在游戏场景类HelloWorld.cpp中用这个实例类的对象去调用我们自定义的方法

stu = Student::create();
sno = stu->getSno();

05-11 10:53
查看更多