Is D so powerfull ??

Jeremy DeHaan via Digitalmars-d digitalmars-d at puremagic.com
Sun Nov 8 21:05:28 PST 2015


On Sunday, 8 November 2015 at 23:43:42 UTC, ZombineDev wrote:
> On Saturday, 7 November 2015 at 21:02:26 UTC, Jeremy DeHaan 
> wrote:
>> On Saturday, 7 November 2015 at 14:49:05 UTC, ZombineDev wrote:
>>> On Saturday, 7 November 2015 at 14:25:01 UTC, ZombineDev 
>>> wrote:
>>>>
>>>> What standard C does not provide and D does: calling C++ 
>>>> free functions nested in namespaces, creating objects of C++ 
>>>> classes (with single inheritance), ...
>>> ... calling virtual and non-virtual methods on C++ classes 
>>> from D
>>
>> Actually, you can only call virtual methods on classes. Using 
>> non-virtual methods isn't supported.
>
> Why do you think so?
>
> See: https://gist.github.com/ZombineDev/19f966273b4a82a5c2f1
> Output:
>
> $ g++ --version
> g++ (Ubuntu 4.9.2-10ubuntu13) 4.9.2
> Copyright (C) 2014 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  
> There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A 
> PARTICULAR PURPOSE.
> $ dmd --version
> DMD64 D Compiler v2.069.0-b2
> Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
> $ ./build.sh
> $ ./d_class
> cpp.add(40, 2): 42
> cpp.mul(1.5, 2f, 'B') 198
> $ ./cpp_main
> d.add(7, 8): 15
> d.mul(3.0, 2.0f, 'A'): 390


Because that's what this page says:
http://dlang.org/cpp_interface.html

It's about halfway down, but here's the section I am referring to 
says:

Note:

     non-virtual functions, and static member functions, cannot be 
accessed.

That's awesome if I am wrong, but that is what the C++ 
interfacing page says.

Declaring it as a struct in D code is freaking genius. I wonder 
if that works across the board with other compilers and OS's 
though.




More information about the Digitalmars-d mailing list