Are out-of-class-declaration method definitions allowed?

Steven Schveighoffer schveiguy at yahoo.com
Fri Nov 13 04:10:52 PST 2009


On Thu, 12 Nov 2009 23:19:21 -0500, AJ <aj at nospam.net> wrote:

>    I can't imagine anyone that knows D doesn't also know C++, but the
> opposite is hardly true, so here's some valid C++ that I'm wondering if
> there is an equivalent style allowed in D:
>
> class MyClass
> {
>   public:
>    void DoIt();
> };
>
> void MyClass::DoIt()
> {
>     // do it
> }

You can define MyClass in a .di file without implementations, and then  
rewrite it in the .d file with implementations.  That's about as close as  
you can get.

>    (Aside: D has no 'inline' keyword, correct? And, should I post  
> questions
> like this post in the learn group? Even if the potential is likely that a
> language design discussion may result?)

d.learn is probably the right place, though most people look at both.   
You'll get the occasional OCD post about how newbie questions really  
should be on d.learn, but it doesn't bother me :)

inlining is done automatically by the compiler as long as it can see the  
entire function source and you pass the -inline command line switch to the  
compiler.

The theory being -- the compiler probably knows better what things are  
good to inline.  In practice, this sometimes isn't the case, but it's all  
we have to work with right now.

-Steve



More information about the Digitalmars-d mailing list