Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 代码块和g++;“错误”;“是私人的”;_C++_C++11_G++_Codeblocks - Fatal编程技术网

C++ 代码块和g++;“错误”;“是私人的”;

C++ 代码块和g++;“错误”;“是私人的”;,c++,c++11,g++,codeblocks,C++,C++11,G++,Codeblocks,我在代码块IDE(使用g++编译器)中遇到了这些错误 对于每个成员变量,“是私有的”。据我所知,在其他成员中使用私有变量是合法的,这就是我正在做的。这是我的cpp的代码: /* bullsAndCows.cpp */ using namespace std; //enum class state {_bull, _cow, _none}; class bullsAndCows { private: const int m_size{4}; bool m_guessed{fa

我在代码块IDE(使用g++编译器)中遇到了这些错误 对于每个成员变量,“是私有的”。据我所知,在其他成员中使用私有变量是合法的,这就是我正在做的。这是我的cpp的代码:

/*
bullsAndCows.cpp
*/

using namespace std;

//enum class state {_bull, _cow, _none};

class bullsAndCows {
private:
    const int m_size{4};
    bool m_guessed{false};
    std::vector<char> m_digit;
    std::vector<state> m_digitState;

public:
    bullsAndCows() {
        m_guessed = false;
        for(int i = 0; i < m_size; i++)
            m_digitState[i] = state._none;
    }

    void bullsAndCows::setGuessed(bool value) { _guessed = value; }
    bool bullsAndCows::getGuessed() { return _guessed; }
    void bullsAndCows::setDigit(char value, int i) { m_digit[i] = value; }
    char bullsAndCows::getDigit(int i) { return m_digit[i]; }
    void bullsAndCows::setDigitState(state value, int i) { m_digitState[i] = value; }
    state bullsAndCows::getDigitState(int i) { return m_digitState[i]; }
};
/*
牛群
*/
使用名称空间std;
//枚举类状态{{u bull,{u cow,{u none};
牛群和奶牛{
私人:
常量int m_size{4};
布尔·穆猜{false};
std::向量m_位;
std::向量m_数字状态;
公众:
牛群和奶牛(){
m_猜测=错误;
对于(int i=0;i
这是我的main代码,我正在测试:

#include "bullsAndCows.h"

using namespace std;

int main()
{
    bullsAndCows game;
    for(int i = 0; i < game.m_size; i++) {
        cin >> game.m_digit[i];
        cout << game.m_digit[i];
    }

    return 0;
}
#包括“bullsAndCows.h”
使用名称空间std;
int main()
{
斗牛士游戏;
对于(int i=0;i>game.m_数字[i];

cout编译器是正确的。
声明:

cin >> game.m_digit[i];
正在访问私人成员:

class bullsAndCows {
private:
    const int m_size{4};
    bool m_guessed{false};
    std::vector<char> m_digit;
    std::vector<state> m_digitState;
牛群和奶牛类{
私人:
常量int m_size{4};
布尔·穆猜{false};
std::向量m_位;
std::向量m_数字状态;
私有成员只能通过类内的方法访问,不能通过外部实体访问,如
main
函数

你的选择是:

  • 创建getter和setter方法
  • 重载流提取运算符>>用于类
    bullsAndCows
  • 公开变量

编译器是正确的。
声明:

cin >> game.m_digit[i];
正在访问私人成员:

class bullsAndCows {
private:
    const int m_size{4};
    bool m_guessed{false};
    std::vector<char> m_digit;
    std::vector<state> m_digitState;
牛群和奶牛类{
私人:
常量int m_size{4};
布尔·穆猜{false};
std::向量m_位;
std::向量m_数字状态;
私有成员只能通过类内的方法访问,不能通过外部实体访问,如
main
函数

你的选择是:

  • 创建getter和setter方法
  • 重载流提取运算符>>用于类
    bullsAndCows
  • 公开变量

编译器是正确的。
声明:

cin >> game.m_digit[i];
正在访问私人成员:

class bullsAndCows {
private:
    const int m_size{4};
    bool m_guessed{false};
    std::vector<char> m_digit;
    std::vector<state> m_digitState;
牛群和奶牛类{
私人:
常量int m_size{4};
布尔·穆猜{false};
std::向量m_位;
std::向量m_数字状态;
私有成员只能通过类内的方法访问,不能通过外部实体访问,如
main
函数

你的选择是:

  • 创建getter和setter方法
  • 重载流提取运算符>>用于类
    bullsAndCows
  • 公开变量

编译器是正确的。
声明:

cin >> game.m_digit[i];
正在访问私人成员:

class bullsAndCows {
private:
    const int m_size{4};
    bool m_guessed{false};
    std::vector<char> m_digit;
    std::vector<state> m_digitState;
牛群和奶牛类{
私人:
常量int m_size{4};
布尔·穆猜{false};
std::向量m_位;
std::向量m_数字状态;
私有成员只能通过类内的方法访问,不能通过外部实体访问,如
main
函数

你的选择是:

  • 创建getter和setter方法
  • 重载流提取运算符>>用于类
    bullsAndCows
  • 公开变量

main()函数尝试将game.m_digit传送到cout,并从cin读取。main无法看到m_digit,因为它是私有的。请尝试读取临时变量,然后根据类的接口调用setDigit()和getDigit()。main()函数函数尝试将game.m_digit传输到cout,并从cin中读取它。Main无法看到m_digit,因为它是私有的。请尝试读取临时变量,然后根据类的接口调用setDigit()和getDigit()。Main()函数尝试将game.m_digit传输到cout,并从cin中读取它。Main无法看到m_digit,因为它是私有的。请尝试读取临时变量,然后根据类的接口调用setDigit()和getDigit()。Main()函数尝试将game.m_digit传输到cout,并从cin中读取它。Main无法看到m_digit,因为它是私有的。请尝试读取临时变量,然后调用setDigit()和getDigit()根据类的接口。已经有一些getter方法,它们只是没有被调用:)已经有一些getter方法,它们只是没有被调用:)已经有一些getter方法,它们只是没有被调用:)已经有一些getter方法,它们只是没有被调用:)