我尝试编译我的代码,我很确定我在标题或编译中犯了错误,但我不明白在哪里。我知道这是一个基本问题,我读了一些其他主题,但我真的不明白。我看了我写的其他一些代码,但没有发现任何区别......
g++ -c main.cpp -o out
我不明白这个错误,所以我也尝试:
g++ -c readFastqFile.cpp
错误
readFastqFile.cpp:8:1: error: ‘readFastq’ does not name a type
readFastq::readFastq(){ //Constructor
我的文件是:
main.cpp
#include <iostream>
#include <string>
#include "readFastqFile.hpp"
using namespace std;
int main(int argc, char *argv[]){
cout << "hello" <<endl;
//readFastq allReads;
return 0;
}
readFastqFile.hpp
#ifdef READFASTQFILE_HPP
#define READFASTQFILE_HPP
#include <iostream>
#include <string>
using namespace std;
class readFastq{
public:
readFastq(); //constructor
private:
string readName;
string sequence;
string score;
};
#endif // READFASTQFILE_HPP
readFastqFile.cpp
#include <string>
#include <iostream>
#include "readFastqFile.hpp"
using namespace std;
readFastq::readFastq(){ //Constructor
readName = "bla";
cout << readName <<endl;
}
谢谢
最佳答案
#ifdef READFASTQFILE_HPP
应为 #ifndef READFASTQFILE_HPP
。 #ifdef
导致 readFastqFile.hpp 的内容被忽略,因此不会编译类定义。
另请参阅Include guards
关于C++ 不在构造函数定义中命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632476/