Hi,
I'm trying to create a named constructor for my class Matrix, with an input as a stream from which I can read the values for the initialization.
#include <istream>
// ...
class Matrix
{
public:
Matrix(int);
// some methods
static Matrix *newFromStream(istream&);
private:
int n;
std::valarray< Cell > data;
};
The method should be implemented more or less like this
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;
}
However, while compiling, I get an error in the declaration of the method (line 74 is where the prototype is defined, and 107 where the implementation starts)
hitori.h:74: error: expected ‘;’ before ‘(’ token
hitori.cpp:107: error: no ‘Matrix* Matrix::newFromStream(std::istream&)’ member function declared in class ‘Matrix’
These errors, however, I do not get when defining and implementing a named constructor with a simple parameter, like an int.
What am I missing? Any help would be greatly appreciated.