Skip to content

Commit 3613865

Browse files
committed
Add Inheritance in C++
1 parent 363883d commit 3613865

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

HelloWorld/src/Main.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,32 @@ class Entity
55
public:
66
float X, Y;
77

8-
Entity()
8+
void Move(float xa, float ya)
99
{
10-
X = 0.0f;
11-
Y = 0.0f;
12-
std::cout << "Created Entity!" << std::endl;
10+
X += xa;
11+
Y += ya;
1312
}
13+
};
1414

15-
~Entity()
16-
{
17-
std::cout << "Destroyed Entity!" << std::endl;
18-
}
15+
class Player : public Entity
16+
{
17+
public:
18+
const char* Name;
1919

20-
void Print()
20+
void PrintName()
2121
{
22-
std::cout << X << ", " << Y << std::endl;
22+
std::cout << Name << std::endl;
2323
}
2424
};
2525

26-
void Function()
27-
{
28-
Entity e;
29-
e.Print();
30-
}
31-
3226
int main()
3327
{
34-
Function();
28+
std::cout << sizeof(Entity) << std::endl;
29+
std::cout << sizeof(Player) << std::endl;
30+
31+
Player player;
32+
player.Move(5, 5);
33+
player.X = 2;
3534

3635
std::cin.get();
3736
}

0 commit comments

Comments
 (0)