C++ 不在构造函数定义中命名类型

C++ does not name a type in Constructor definition

我尝试编译我的代码,我很确定我在我的 headers 或编译中犯了一个错误,但我不明白在哪里。我知道这是一个基本问题,我也看了一些其他的题目,但我真的不明白。我看了我写的一些其他代码,没有发现任何区别...

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 的内容被忽略,因此未编译 class 定义。

另见 Include guards