小编Lev*_*han的帖子

无法更改私有变量的内容

main.cpp:

#include <iostream>
#include <string>
#include "Players.h"
using namespace std;

int main ()
{
    cout << "**** Welcome to Leviathan's first TicTacToe Game! ****\n\n";
    Players getNamesobject;
    Players printNamesobject;
    getNamesobject.getPlayersNames();
    printNamesobject.printPlayersNames();

}
Run Code Online (Sandbox Code Playgroud)

Players.h:

#ifndef PLAYERS_H
#define PLAYERS_H


class Players
{
    public:
        void getPlayersNames();
        void printPlayersNames();
    private:
        std::string _player1Name;
        std::string _player2Name;
};

#endif // PLAYERS_H
Run Code Online (Sandbox Code Playgroud)

Players.cpp:

#include <iostream>
#include <string>
#include "Players.h"
using namespace std;

void Players::getPlayersNames()
{
    string p1,p2;
    cout << "Enter player 1 name : ";
    cin >> p1;
    cout …
Run Code Online (Sandbox Code Playgroud)

c++ variables private class object

2
推荐指数
1
解决办法
126
查看次数

标签 统计

c++ ×1

class ×1

object ×1

private ×1

variables ×1