#include <iostream>
//struct visibility by default: public.
//class visibility by default: private.
class classPlayer
{
public:
double m_x;
double m_y;
double m_speed;
private:
void Move(double a, double b)
{
m_x += a * m_speed;
m_y += b * m_speed;
}
};
struct structPlayer
{
double m_x;
double m_y;
double m_speed;
private:
void Move(double a, double b)
{
m_x += a * m_speed;
m_y += b * m_speed;
}
};
struct Vector
{
float x, y;
void Add(const Vector& other)
{
x += other.x;
y += other.y;
}
};
int main(void)
{
classPlayer player;
player.m_x = 5;
player.m_y = 4;
std::cin.get();
}
【Cherno的C++视频】Classes vs structs in C++
最新推荐文章于 2024-03-22 11:41:34 发布