Is it possible to define methods outside the class in C ++ style? Something like this:
class Parent{
void Print();
}
void Parent.Print(){
writeln("Hello, D!");
}
Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
July 21, 2021 Method definition | ||||
---|---|---|---|---|
| ||||
Is it possible to define methods outside the class in C ++ style? Something like this:
|
July 21, 2021 Re: Method definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tim Gunesh | On Wednesday, 21 July 2021 at 12:08:21 UTC, Tim Gunesh wrote: >Is it possible to define methods outside the class in C ++ style? Something like this:
No, it's not possible. However, uniform function call syntax allows functions defined outside of a class to be called as though they were methods. For example:
|
July 21, 2021 Re: Method definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tim Gunesh | On Wednesday, 21 July 2021 at 12:08:21 UTC, Tim Gunesh wrote: >Is it possible to define methods outside the class in C ++ style? Something like this:
No and it doesn't make much sense to do so. The reason why you have to do in C++ is because of header files and source files are separate. Since D uses modules then definition and implementation doesn't have to be separated. |
July 21, 2021 Re: Method definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tim Gunesh | On Wednesday, 21 July 2021 at 12:08:21 UTC, Tim Gunesh wrote: >Is it possible to define methods outside the class in C ++ style? Something like this:
I was afraid that this is not possible. I'm partly used to this convenience in C++. This allows you to quickly understand the content of the class, especially in large undocumented projects. I'd love to move this to D. Thanks everyone for the reply and thanks to Paul Backus for an alternative way of defining methods! |
July 21, 2021 Re: Method definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tim Gunesh | On Wednesday, 21 July 2021 at 13:56:11 UTC, Tim Gunesh wrote: >This allows you to quickly understand the content of the class, especially in large undocumented projects. The D compiler can auto-generate listings like that. dmd -H makes a .di file with the bodies stripped out you can pursue, or a documentation generator like my adrdox can make HTML files with the method prototypes, even if there are no other docs (use --document-undocumented arg to adrdox for that). So you can accomplish these goals through other means. |
July 21, 2021 Re: Method definition | ||||
---|---|---|---|---|
| ||||
Posted in reply to Adam D Ruppe | On Wednesday, 21 July 2021 at 14:02:42 UTC, Adam D Ruppe wrote: >On Wednesday, 21 July 2021 at 13:56:11 UTC, Tim Gunesh wrote: >This allows you to quickly understand the content of the class, especially in large undocumented projects. The D compiler can auto-generate listings like that. dmd -H makes a .di file with the bodies stripped out you can pursue, or a documentation generator like my adrdox can make HTML files with the method prototypes, even if there are no other docs (use --document-undocumented arg to adrdox for that). So you can accomplish these goals through other means. Lots of thanks Adam! I'm new to D and this is the language I fell in love with the first time :). And tools like yours (https://github.com/adamdruppe/adrdox) are important to me. |