[C++] Trying to play around with classes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

[C++] Trying to play around with classes

Sup there So i'm pretty new to OOP and i'm trying to play around with it I have done a mini shooting game around 2 player from the class made : https://pastebin.com/6m6NjYai I'm pretty noob so you guys have some ajustement to do. Btw if like the player want to add another player, do i need to create another string that store the player3 name then create a p3.name from that or i can do it directly from what the player typing ? like (p3.name = cin ?) I did not make the player 2 interact yet he he just here to take damages.

10th Aug 2019, 10:40 AM
Charles Constantinesco
Charles Constantinesco - avatar
5 Answers
+ 3
Charles C in case life can be set and get like in ~ swim ~ example, yes, even though some would say it is not a good way of doing. In case it has rules to be set, no
10th Aug 2019, 2:42 PM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
@~ swim ~ And how can i make my player object global ? Like if i create another function. How can i call p1 created on the main on it ?
10th Aug 2019, 11:35 AM
Charles Constantinesco
Charles Constantinesco - avatar
+ 1
@~ swim ~ Yeah i come from C and objet is not really clear for me yet. But as far as i know they are more useful than struct
10th Aug 2019, 3:09 PM
Charles Constantinesco
Charles Constantinesco - avatar
0
~ swim ~ i dont get are get and set function.
10th Aug 2019, 2:13 PM
Charles Constantinesco
Charles Constantinesco - avatar
0
Isnt is just faster to put the life in public and just p1.life ?
10th Aug 2019, 2:19 PM
Charles Constantinesco
Charles Constantinesco - avatar