Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 类的转发声明:语法错误_C++_Class_Inheritance_Header Files_Turbo C++ - Fatal编程技术网

C++ 类的转发声明:语法错误

C++ 类的转发声明:语法错误,c++,class,inheritance,header-files,turbo-c++,C++,Class,Inheritance,Header Files,Turbo C++,以下代码中出现声明语法错误: fileio.h fileio.cpp Test.cpp 我不明白为什么会发生这种情况…转发声明对于解析声明中的指针和引用类型很好 但是,编译器在编译函数时需要完整的类型定义。您收到的确切错误是什么?请在前面显示行。前向声明不能让您创建类似fileio Object_1;的实例;。请帮自己一个忙,从当前的千年中获得一个编译器。您希望您的fileio.cpp如何准确地了解在完全不同的翻译单元中定义的类的成员,这些翻译单元可能会被编译,也可能不会被编译?为了定义file

以下代码中出现声明语法错误:

fileio.h

fileio.cpp

Test.cpp


我不明白为什么会发生这种情况…

转发声明对于解析声明中的指针和引用类型很好


但是,编译器在编译函数时需要完整的类型定义。

您收到的确切错误是什么?请在前面显示行。前向声明不能让您创建类似fileio Object_1;的实例;。请帮自己一个忙,从当前的千年中获得一个编译器。您希望您的fileio.cpp如何准确地了解在完全不同的翻译单元中定义的类的成员,这些翻译单元可能会被编译,也可能不会被编译?为了定义fileio对象_1;您需要知道的不仅仅是类的名称。必须完全声明该类。
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
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;
}
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(); 
     }
};