我有一个文件 SpreadSheetCell.h 和 SpreadSheetCell.cpp。
我有另一个文件 SpreadSheet.cpp 其中包括 SpreadSheetCell.h 。在这种情况下,它给我错误,例如“对 SpreadSheetCell:SpreadSheetCell() 的 undefined reference ”等。
但是当我尝试包含 SpreadSheetCell.cpp 时,而不是错误消失了。包含头文件而不是 cpp 文件不是很常见吗?我可能做错了什么?
最佳答案
这是一个链接错误,意味着您在编译时没有包含具有 SpreadSheetCell:SpreadSheetCell()
定义的源文件。
您使用的命令行中可能缺少 SpreadSheetCell.cpp
,例如像这样:
g++ -o myBinary SpreadSheet.cpp SpreadSheetCell.cpp [...more files?]
关于c++ - 在 .cpp 文件中包含头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9186649/