【发布时间】:2018-03-24 01:09:58
【问题描述】:
我有一个类,我不知道如何解决.cc文件中的错误进行编译
.h 文件的摘录以在 .h 文件中显示板
class sudokuboard {
private:
/*** Member data ***/
char board[9][9];
.cc 文件部分给我带来了麻烦
sudokuboard::sudokuboard()
{
for (size_t r = 0; r < 9; r++){
for (size_t c = 0; c < 9; c++)
board[r][c] = '_';
}
}
void sudokuboard::print() const
// write the board to cout
{
for (size_t r = 0; r < 9; r++){
string colStr = "";
for (size_t c = 0; c < 9; c++){
colStr += board.get(r, c);
}
cout << colStr << endl;
}
void sudokuboard::remove(size_t r, size_t c)
// remove the numeral at position (r,c)
{
board[r][c] = "_";
}
ERRORS:
sudokuboard.cc: In member function ‘void sudokuboard::print() const’:
sudokuboard.cc:26: error: request for member ‘get’ in ‘((const
sudokuboard*)this)->sudokuboard::board’, which is of non-class type
‘const char [9][9]’
sudokuboard.cc: In member function ‘void sudokuboard::remove(size_t,
size_t)’:
sudokuboard.cc:42: error: invalid conversion from ‘const char*’ to ‘char’
sudokuboard.cc:59: error: request for member ‘get’ in ‘((const
sudokuboard*)this)->sudokuboard::board’, which is of non-class type ‘const
char [9][9]’
我不知道该改变什么了。我尝试了很多不同的方法。
【问题讨论】:
-
数组中没有方法
get,所以board.get可能只是sudokuboard的get方法。"_"是字符串字面量,应该是'_'。