ヘッダーがあります:iostream、fstream、 iomanip main()
、MyClass.h
char temp;
MyClass *class1;
ifstream inf("file")
while(inf >> temp)
{
if(temp == 'A') class1 = new Myclass();
inf >> *class1;
}
Myclass.hの場合:
class MyClass{
int num;
protected:
virtual istream& read(istream &is)
{ /* char temp; is >> temp >> num; */
return is; //seg faults on this line I believe
}
public:
friend istream& operator >> (istream &is, MyClass &class1) {return class1.read(is);}
};
プログラムはファイルを読み取り、それがで始まるかどうかを確認してから'a'
、クラスを作成し、そのファイルに情報を解析する必要があります。次にMyClass
、istreamを読み取り関数に渡します。ここでセグメンテーション違反が発生します。whileループに入るときと同じように、セグメンテーション違反をプログラムします。仮想読み取り機能を削除しても、セグメンテーション違反は発生しません。gdbは??で0x000000001を指しているだけです
これは宿題の問題であり、read()
(およびその他の)関数の本文を作成する必要があります。