Function implemented outside the class
MarisaLovesUsAll
marusya at 2ch.hk
Mon Mar 24 13:02:25 PDT 2014
On Monday, 24 March 2014 at 01:34:22 UTC, Matej Nanut wrote:
> 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.
2 all:
Thanks for replies!
> Why would you like to do that?
I planned to use it to take event handling out from class (and
put it in another file), but now I see that isn't a good idea.
class App
{
void updateEvents(SDL_Event event) { ... }
}
By the way, it would be useful if it was written somewhere that
implementation outside the class is impossible.
Sorry for bad English.
Regards,
Alexey
More information about the Digitalmars-d-learn
mailing list