Topic: Static operators?


Author: jason@cygnus.com (Jason Merrill)
Date: Mon, 23 May 1994 02:13:44 GMT
Raw View
>>>>> Cay Horstmann <horstman@sjsumcs.sjsu.edu> writes:

> Can an operator function be a static member function to a class?

No.  By making it a static member you would restrict its scope to other
members (and rewritten friends), which was evidently deemed confusing and
consequently disallowed.

Jason




Author: horstman@sjsumcs.sjsu.edu (Cay Horstmann)
Date: 22 May 1994 14:19:41 GMT
Raw View
Can an operator function be a static member function to a class?

 class X
 {
  // ...
  static int operator==(const X&, const X&);
 };

 int X::operator==(const X& a, const X& b) { ... }

Some "advantages": the operator function has access to the private
features of the class without having to be a friend... you get access
control, that is by declaring the operator in the private or protected
section you restrict its usage...

I am NOT advocating that this should be legal, nor do I care whether a
specific compiler currently accepts or rejects it. I merely would like to
know what the standard is likely to say regarding this issue.

Cay
horstman@cs.sjsu.edu