班级的正向声明:语法错误

Forward Declaration of Class: Syntax Error

本文关键字:语法 错误 声明      更新时间:2023-10-16

我在以下代码中获得声明语法错误:

fileio.h

class fileio;  //ERROR HERE: I'm trying to declare it so I can use it in read() function
int read(char* file_1);   //File Read Function

fileio.cpp

int read(char* file_1) {   //File Read Function
    fileio Object_1;
    int records_read=0;
    ifstream fin;
    fin.open(file_1, ios::binary);   //Opens the file again
    while(fin.read((char*)& Object_1, sizeof(Object_1))) { 
        records_read++;
        Object_1.show_tablular();
    }
    fin.close();
    return records_read;
}

test.cpp

template <class T>
void AddColumn(T data, const int& width) {
    cout<<setw(width)<<data<<" | ";
}
void Test_Class::show_tablular() {
    cout<<endl; AddColumn(record_id,7); AddColumn(char_member, 20); AddColumn(int_member, 11); AddColumn(float_member, 13);
}

内部()

 class fileio : public Test_Class {   //Trying to relate the 2 classes
  public:
     void show_tablular() {
         Test_Class::show_tablular(); 
     }
};

我不明白为什么会发生...

正向声明对于解决声明中的指针和参考类型是可以的。

但是,编译器在编译功能时需要对类型的完整定义。