October 27, 2015 how use * in D just like C++ | ||||
|---|---|---|---|---|
| ||||
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!!!!!
| ||||
October 27, 2015 Re: how use * in D just like C++ | ||||
|---|---|---|---|---|
| ||||
Posted in reply to liumao | 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. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply