和Java中的概念基本相同,看下怎么写就行
#include <iostream>
class Entity {
public:
float mX = 0.0f;
float mY = 0.0f;
void move(float dx, float dy) {
mX += dx;
mY += dy;
}
void printPosition() {
std::cout << mX << "," << mY << endl;
}
};
class Player : public Entity {
public:
const char *mName = "Player";
void printName() {
std::cout << mName << std::endl;
}
};
int main() {
Player player;
player.printName();
player.move(5, 8);
player.printPosition();
return 0;
}
F:\Projects\ClionProjects\test\cmake-build-debug-cygwin\test.exe
Player
5,8
进程已结束,退出代码为 0