Function implemented outside the class

Matej Nanut matejnanut at gmail.com
Sun Mar 23 15:16:58 PDT 2014


Hello!

You can implement static functions that act like members, like so:

---
void myFunc(MyClass c) { ... }
---

Which you will be able to call like:

---
auto c = new MyClass();
c.myFunc();
---

because of uniform function call syntax (UFCS).

But they won't be real methods (virtual member functions), which means they
can't be overridden.

Note that you can use the class's private members in such functions,
because private things in D are private to the file (module) instead of the
containing class or struct.

I don't think it's possible to do the same thing as in C++ though; but I
might be wrong.

Why would you like to do that?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20140323/32483a2f/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list