Cpp:
The struct the default is public that is the only difference between a
struct and a class
#include <iostream>
using namespace std;
struct s1
{
int x,y;
int speed;
void move(int xa,int ya)
{
x += xa * speed;
y += ya * speed;
cout << x << " " << y << endl;
}
};
// struct default is public, class default is private
// If s1 is a class, we will get an error from int main()
// because move() will be inaccessible
int main()
{
s1 s1;
s1.x = 1;
s1.y = 2;
s1.speed = 5;
s1.move(1, 1);
system("pause");
return 0;
}
struct default is public, class default is private
If s1 is a class, we will get an error from int main()
because move() will be inaccessible