C++ 我的设置函数中的值没有更改
C++ 我的设置函数中的值没有更改,c++,arrays,getter-setter,C++,Arrays,Getter Setter,n的值正在传递给myvoid Cell::setValue(int value)函数,但m_值不会更改。有人能解释一下这里出了什么问题吗 文件读入 void SudokuPuzzle::readPuzzle(const char filenameIn[]) { // Add code to read in a puzzle from the text file and store within the SudokuPuzzle object ifstream inStream; inStream
n
的值正在传递给myvoid Cell::setValue(int value)
函数,但m_值
不会更改。有人能解释一下这里出了什么问题吗
文件读入
void SudokuPuzzle::readPuzzle(const char filenameIn[]) {
// Add code to read in a puzzle from the text file and store within the SudokuPuzzle object
ifstream inStream;
inStream.open(filenameIn);
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
int n;
inStream >> n;
m_grid[i][j].setValue(n);
}
}
例如,当n
设置为3
时,它将传递到值
m_value=value
在这种情况下不会将m_value
设置为3
:
if (m_value = 0)
尽管m_值
之前被分配了value
的值,但它在这里被分配了值0
您可能打算将m_值
与0
进行比较,如下所示:
if (m_value == 0)
如果您打开编译器警告(例如,使用-Wall
),您将被告知此代码可能是一个bug。@Const再次,如果您打开警告,编译器将告诉您,您不必注意它:)
if (m_value == 0)