Vishaal Shankar
Vishaal Shankar

Reputation: 1658

Commented parameter in function

I was going through the implementation of seekpos in the source of streambuf in the gnu online doc. I couldn't understand why __mode is commented in the line ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out and why it doesn't throw an error.

  virtual pos_type 
  seekpos(pos_type, ios_base::openmode /*__mode*/ = ios_base::in | ios_base::out)
   {
      return pos_type(off_type(-1));
   }

I can understand the usage of the comment, if it was of the following format :

void foo( pos_type, int /*blah*/ ){
...
}

But, in the former case, there is also an intention to assign something to __mode, hence my surprise on not getting any error there.

Is this allowed? If yes, then why ?

Upvotes: 4

Views: 332

Answers (1)

Some programmer dude
Some programmer dude

Reputation: 409216

First of all it's not an assignment, it's a default argument. And you can have any or even all arguments be anonymous.

If an argument is not used inside the function, you can leave out the variable name, and just have the type, and (as noted) even default arguments. The argument variable name is optional.

Upvotes: 5

Related Questions