2017-09-10 1 views
-2

私は、次のコードで宣言構文エラーを取得しています:前方宣言:構文エラー

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

それが起こっている理由を私は理解していない...

+2

正確なエラーは何ですか? –

+0

その前の行も表示します。 – stark

+0

フォワード宣言で 'fileio Object_1;'のようなインスタンスを作ることはできません。 –

答えて

0

前方宣言は宣言でポインタと参照型を解決するための罰金です。

ただし、関数のコンパイル時にコンパイラは型の完全な定義を必要とします。