Initializing a Reference to a Stream

In my main function I have

ifstream str;
str.open("test_1.json");

Array2D<3,3> cov = covMatrix(str);

Vect<3> mean = meanVect(str);

Then, I also have template function defined below as
Array2D<3,3> covMatrix(istream& stream);
and
Vect<3> meanVect(istream& stream);

I keep getting the error that the two functions are not declared in this scope. The line numbers refer to the function calls in the main function. I'm not sure what to do about this. Do you need to make a reference to a stream? How would I do this? Or is it something else?

Thanks!
Anna
It sounds like you defined the functions after you use them.
Change something like this:
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
    ifstream str;
    str.open("test_1.json");

    Array2D<3,3> cov = covMatrix(str); 

    Vect<3> mean = meanVect(str); 
}

Array2D<3,3> covMatrix(istream& stream);
Vect<3> meanVect(istream& stream);

to this:
1
2
3
4
5
6
7
8
9
10
11
12
Array2D<3,3> covMatrix(istream& stream);
Vect<3> meanVect(istream& stream);

int main()
{
    ifstream str;
    str.open("test_1.json");

    Array2D<3,3> cov = covMatrix(str); 

    Vect<3> mean = meanVect(str); 
}


In C++, everything needs to be declared before it can be used.

If this isn't you problem though, you need to be more clear.
That is it! Thanks!
Topic archived. No new replies allowed.