By using this site, you agree to our Privacy Policy and our Terms of Use. Close

Forums - General - A Little C++ Help Guys?

Alright I have a problem in C++. I'm trying to do some stuff with references to input streams and I end up with errors which I don't get (and which are almost certainly very simple, but google didn't help).


I have a header file which when all of the unimportant stuff is dropped out (the includes and comments and functions which I haven't implemented yet) is essentially this.

[CODE]class WordStream {
public:

private:
    std::ifstream& inFile;  

public:
    WordStream(std::ifstream& fileStream);

};[/CODE]

And the constructor in my .cpp file is as follows.

[CODE]WordStream::WordStream(std::ifstream& fileStream)
{
    inFile = fileStream;
}[/CODE]


When I try and compile I get the error "error C2758: 'WordStream::inFile' : must be initialized in constructor base/member initializer list".

I'm assuming its a problem with what I've done with references here but to be honest I'm pretty well stuck and can't figure out what it is I've stuffed up.  :(
Cheers for any help you guys can give.



Around the Network

Sorry for the blatant bump, but this problem is really irking me. I swear there must a simple solution to this problem but I just can't get my head around it.