编译时出错
Error during compiling
当我编译"main.cpp: In构造函数' TicTacToe::TicTacToe() '时,我收到这个错误:Main.cpp:38:错误:数组被用作初始化器"有线索吗?"谢谢。
class chicken {
public:
chicken() : board("123456789") {};
private:
char board[10];
char player; // Switch after each move.
};
不能这样初始化数组。请使用strcpy。
TicTacToe() {
strcpy(board,"123456789")
}
或者使用std::string来使用构造函数初始化式
class TicTacToe {
public:
TicTacToe() : board("123456789") // Ok
{};
private:
std::string board ; // Changed to string type. There is no good reason to use
// character array when string type is available.
};
"123456789"有10个字符,因为末尾有一个NULL。
相关文章:
- 在Linux for Windows上编译C++代码时出错
- 为x86而非x64编译时出错
- 当我尝试通过 mingw 使用 CMake 和 SFML 库编译项目时出错
- 尝试在Windows上执行C++时出错(通过MinGW编译)
- 如何使用我构建的库,而不会从源代码出错,但不为我自己的项目编译?
- constexpr 使用 clang 编译 TensorFlow 时出错
- 从DLL导出函数,LoadLibrary()需要用TEXT转换的字符串才能编译而不会出错
- 编译包含指向模板函数的指针的初始值设定项列表时,gcc 出错,但 clang 不出错
- 编译时出错 - 从 DWORD 到 LPCVOID 的转换
- 在发布模式下启动使用库的静态链接编译的应用程序时出错
- 编译时出错 - 链接.cpp和头文件
- <limits> 使用 VSC2019 编译旧代码时出错
- 在 ubuntu 焦点上编译虚幻引擎 4.25 时出错
- 编译包含LLVM API标头的C++文件时出错
- 编译以下代码时出错
- 使用交叉工具ng编译gcc时出错
- 在 dll 中为 qLibrary 编译 qobject 时出错
- 使用 cmake 在窗口上编译 c++ 数据库时出错
- 使用 TDM GCC 5.1.0 编译 PDCurses36 时出错
- Lua :在原生lua中编译,但在使用LuaJIT和sol2时C++出错