how use * in D just like C++

Jakob Ovrum via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 26 23:14:08 PDT 2015


On Tuesday, 27 October 2015 at 05:36:58 UTC, liumao wrote:
> for example
>     class A;
>     {
>         void doSomething() {}
>     }
>
>     A *a = cast(A *) new A;
>
>     then I call a.doSomething(); my program "Segmentation fault"
>
>
>
> how could it happened? and how i use it correctly?
>
>
> 3q, please tell me, 3q 3q 3q!!!!!

`A` on its own is already a reference type. `A*` is a pointer to 
a class reference, i.e. a pointer to a pointer, like `A**` in C++.

http://wiki.dlang.org/Coming_From/C_Plus_Plus#Slicing_problem

Please use D.learn for questions like this in the future.



More information about the Digitalmars-d mailing list