初期化の値を読み取ることができるストリームとしての入力を使用して、クラス Matrix の名前付きコンストラクターを作成しようとしています。
#include <istream>
// ...
class Matrix
{
public:
Matrix(int);
// some methods
static Matrix *newFromStream(istream&);
private:
int n;
std::valarray< Cell > data;
};
メソッドは多かれ少なかれこのように実装する必要があります
Matrix *Matrix::newFromStream(istream &ist) {
// read first line and determine how many numbers there are
string s;
getline( ist, s );
...
istringstream iss( s, istringstream::in);
int n = 0, k = 0;
while ( iss >> k)
n++;
Matrix *m = new Matrix( n );
// read some more values from ist and initialize
return m;
}
しかし、コンパイル中にメソッドの宣言でエラーが発生します (74 行目でプロトタイプが定義され、107 行目で実装が開始されます)。
hitori.h:74: error: expected ‘;’ before ‘(’ token
hitori.cpp:107: error: no ‘Matrix* Matrix::newFromStream(std::istream&)’ member function declared in class ‘Matrix’
ただし、これらのエラーは、int などの単純なパラメーターを使用して名前付きコンストラクターを定義および実装する場合には発生しません。
私は何が欠けていますか?どんな助けでも大歓迎です。