Constructor class:

Play(char *m [15], char *f [15], bool a) { name_male = &m;//name_male - поле класса name_female = &f;//name_female - поле класса a_enable = a; } 

And in main :

 cin >> male; cout << "Введите имя девочки: "; cin >> female; Play Game(male, female, 0); Game.Menu(); 

But an error is being written. How to pass a string to a constructor?

    1 answer 1

    Here everything is wrong. Use std::string .

     std::string male,female; Play(const std::string& m, const std::string& f, bool a) { name_male = m;//name_male - поле класса name_female = f;//name_female - поле класса a_enable = a; } 
    • Very correct answer. In C ++, the string is std::string , char* used only for optimization and interaction with the outside world. - VladD
    • @VladD why shouldn't char be used? - neko69
    • @ neko69: From a C ++ point of view, char* too low-level, since it requires manual memory management. You have to think who selected it, who should copy and who can use it as it is, and who should delete it. With std::string there are no such problems. - VladD
    • @ neko69: Well, std::string simpler and clearer to use. For example, to add several char* lines, you need to manually calculate their sizes ( strlen ), allocate the necessary amount of memory ( malloc , do not forget to add one to the sum!), Copy all the lines into the resulting buffer ( strcpy ), not forgetting where the next line should go. For std::string this is just + . - VladD
    • @ neko69: With std::string you lose in efficiency, but you win in the simplicity of the code (and therefore reliability). - VladD