Problem returning a reference to a file with a get method

Jul 27, 2012 at 6:00am
Hi guys, I have a class whose one of it's methods has the purpose of return a reference to a private ifstream member. This one:

1
2
3
ifstream& FileManager::getFileReader () {
  return &fileReader;
}


Unfortunatelly it's generating this error message
FileManager.cpp:12: error: invalid initialization of non-const reference of
type 'std::ifstream&' from a temporary of type 'std::ifstream*'


Can anyone explain it to me? Thanks.
Jul 27, 2012 at 6:12am
Don't return the address of fileReader. Just return fileReader itself.
Jul 27, 2012 at 7:09am
&fileReader returns a pointer to that type.
Topic archived. No new replies allowed.