Forward Declaration of Class: Syntax Error

1.1k Views Asked by At

I'm getting a declaration syntax error in the following code:

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);
}

inside main()

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

I don't understand why it's happening...

1

There are 1 best solutions below

0
On BEST ANSWER

Forward declarations are fine for resolving pointer and reference types in declarations.

However, the compiler needs the complete definition of the types when compiling functions.