www.digitalmars.com         C & C++   DMDScript  

D - static const methods

reply "Sandor Hojtsy" <hojtsy index.hu> writes:
In C++, this was disallowed:

class Someting {
  static void Method() const;
};

It should mean a static method which should not change any of the static
members.
As compared to the allowed:

class Someting {
  void Method() const;
};

Meaning a non-static method, which should not change any of the members.
Does / will D support static const methods?

Yours, Sandor
Aug 06 2002
parent reply "Sean L. Palmer" <seanpalmer earthlink.net> writes:
In D, const is a storage class, not a modifier or attribute.    It's not
part of the type system.

Sean

"Sandor Hojtsy" <hojtsy index.hu> wrote in message
news:aio9j9$hjk$1 digitaldaemon.com...
 In C++, this was disallowed:

 class Someting {
   static void Method() const;
 };

 It should mean a static method which should not change any of the static
 members.
 As compared to the allowed:

 class Someting {
   void Method() const;
 };

 Meaning a non-static method, which should not change any of the members.
 Does / will D support static const methods?

 Yours, Sandor
Aug 07 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
news:aiql5v$13cs$1 digitaldaemon.com...
 In D, const is a storage class, not a modifier or attribute.    It's not
 part of the type system.
Right. The const thing in C/C++ is a good idea, it just never worked out well in practice.
Aug 07 2002
parent reply "Sandor Hojtsy" <hojtsy index.hu> writes:
"Walter" <walter digitalmars.com> wrote in message
news:aisdjh$23t3$1 digitaldaemon.com...
 "Sean L. Palmer" <seanpalmer earthlink.net> wrote in message
 news:aiql5v$13cs$1 digitaldaemon.com...
 In D, const is a storage class, not a modifier or attribute.    It's not
 part of the type system.
Right. The const thing in C/C++ is a good idea, it just never worked out well in practice.
There is no need to call this property "const", if it bothers you. class Someting { void restricted Method(); }; Such a method should be unable to change any member values. I found such restrictions usefull.
Aug 21 2002
parent "Walter" <walter digitalmars.com> writes:
"Sandor Hojtsy" <hojtsy index.hu> wrote in message
news:ajvpgs$g7i$1 digitaldaemon.com...
 There is no need to call this property "const", if it bothers you.

 class Someting {
    void restricted Method();
 };

 Such a method should be unable to change any member values.
 I found such restrictions usefull.
Dealing with const/volatile attributes permeates the C++ spec, and causes a great deal of complexity and implementation grief. The benefit isn't there for the added complexity.
Aug 23 2002