#include <iostream>
class Players {
public:
std::string ppname = "";
std::string pcards = {};
};
void main(){
std::string nameone = "";
std::string nametwo = "";
std::string namethree = "";
std::cout << "player one's name?" << std::endl;
std::cin >> nameone;
std::cout << "player two's name?" << std::endl;
std::cin >> nametwo;
std::cout << "player two's name?" << std::endl;
std::cin >> namethree;
Players playerzero;
Players playerone;
Players playertwo;
playerzero.ppname = nameone;
playerone.ppname = nametwo;
playertwo.ppname = namethree;
}```
#guys is there an more compact way of doing this in the main function
30 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
not by much. but you could add a constructor to Players that takes the name
then the last 6 lines become 3:
Players playerzero(nameone);
Players playerone(nametwo);
Players playertwo(namethree);
Oh wow I see I see
it would help
but how would the constructor function look like?
in the class
class Players {
public:
std::string pcards = {};
std::string ppname = "";
Players(pname) {
ppname = pname;
};
};```
like this?
you can initialize stuff outside the constructor body
class Players {
public:
std::string pcards = {};
std::string ppname = "";
Players(const std::string& pname): ppname{pname} {}
};
ohhh thats so cool i see thank you
missing a :
yeah lol just noticed
@astral zephyr it should also be noted that ppname will only be initialized once. it will not be initialized with "" and then ppname
also missing the type for the constructor parameter
thank you! ill look at it
i realised that a lot of links like those
come from the same tutorial page
i just copy pasta'd their code lol monke brain
its the recommended tutorial
I see I see hmm, yeah thats good enough for the name i guess
I see I see thats great