我正在尝试创建一个在创建时调用其中一个函数的类,但是在编译时出现以下错误:
g++ -std=c++11 -Wall -Wextra -Werror -pedantic-errors -DNDEBUG -c src/PuzzleSolution.cpp
src/PuzzleSolution.cpp:7:32: error: definition of implicitly-declared 'PuzzleSolution::PuzzleSolution()'
PuzzleSolution::PuzzleSolution()
^
src/PuzzleSolution.cpp:12:6: error: prototype for 'void PuzzleSolution::addRow()' does not match any in class 'PuzzleSolution'
void PuzzleSolution::addRow()
^
src/PuzzleSolution.h:19:10: error: candidate is: void PuzzleSolution::addRow(std::vector<unsigned int>&)
explicit PuzzleSolution();
^
src/PuzzleSolution.cpp:17:48: error: no 'void PuzzleSolution::addElement(unsigned int)' member function declared in class 'PuzzleSolution'
void PuzzleSolution::addElement(unsigned int id)
^
make: *** [PuzzleSolution.o] Error 1
这是标题:
#include <vector>
using namespace std;
class PuzzleSolution {
private:
vector<vector<unsigned int>> sol;
public:
explicit PuzzleSolution();
void addRow();
};
这是cpp文件:
#include "PuzzleSolution.h"
PuzzleSolution::PuzzleSolution()
{
addRow();
}
void PuzzleSolution::addRow()
{
this->sol.emplace_back();
}
我究竟做错了什么?
发现问题:
文件src
夹中有一个文件叫PuzzleSolution.h.gch
@Quatin 和 @StoryTeller 帮助我理解这是一个预编译的头文件,编译器一直在使用它。
删除后,项目编译执行
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句