Question

I'm converting my code to follow the google C++ style guide. The Reference Arguments rule says "All parameters passed by reference must be labeled const" and "input arguments are values or const references while output arguments are pointers".

With respect to the signature void MyTable::LoadTable(ifstream &fin), how can I label the parameter fin const given LoadTable invokes some non-const function of fin, e.g. fin.seekg? I think fin should be regarded as an input/output parameter thus it's a little bit special. What will googlers do in this situation?


UPDATE: I knew there are lots of criticisms about the google style guide. I just wondered how googlers tackle it, and maybe I found an answer: there is another rule Streams reading "Use streams only for logging". Maybe they just don't use streams in this situation.

Was it helpful?

Solution

In order to comply with Google guidelines, change the declaration

void MyTable::LoadTable( ifstream& fin )

to

void MyTable::LoadTable( ifstream* fin )

Now you might be wondering, what's the point of that? And a large part of the answer is probably that the Google C++ style guide simply doesn't make much sense outside of Google. Parts of it can be explained by postulating the need to maintain a large body of C style legacy code, but parts of it are just baffling.

As just one example, std::getline is very much in breach of the Google style guidelines.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top