9

I found code in boost similar to:

class A
{
    stats stat;
public:
    int min() const{ return (stat.min)(); }
};

...

int stats::min()
{
...
}

Why are parenthesis here? I know that it can be used for "most vexing parse" and to prohibit ADL. But maybe something else? Thanks in advance!

jww
  • 97,681
  • 90
  • 411
  • 885
user2319183
  • 103
  • 4
  • You mean the `(stat.min)` in the `return (stat.min)();` statement? There's absolutely no need for them, except if the original coder didn't trust the operator precedence to do the right thing (which it does). – Some programmer dude Nov 06 '13 at 11:55
  • It doesn't do anything. They were probably in the habit of wrapping function names in parens to avoid ADL and they just ended up using them here too. – Simple Nov 06 '13 at 11:56
  • cross-reference: http://stackoverflow.com/q/24116817/819272 – TemplateRex Aug 25 '14 at 11:09

1 Answers1

14

It's done because windows.h (Windows platform) has #defines for both min and max. See here for more info: How to tame the Windows headers (useful defines)? and https://stackoverflow.com/a/13420838/297451

Community
  • 1
  • 1
Jon
  • 5,275
  • 5
  • 39
  • 51