On 11/23/17 12:57 AM, Nicholas Wilson wrote:
On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote:
I am a C++ game developer and I want to give it a try.
It seems "this" in Dlang is a reference instead of pointer.
How can I pass it as void *?
void foo(void *);
class Pizza {
public:
On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote:
I am a C++ game developer and I want to give it a try.
It seems "this" in Dlang is a reference instead of pointer.
How can I pass it as void *?
void foo(void *);
class Pizza {
public:
this() {
Pizza newone = this;
On Wednesday, 22 November 2017 at 15:34:53 UTC, Adam D. Ruppe
wrote:
No, in both cases, if you do as I say, you will be passing the
same address.
I was referring to his version of the main function that used &.
But yes, if you do a cast instead it works just as you say.
On Wednesday, 22 November 2017 at 15:36:22 UTC, Adam D. Ruppe
wrote:
On Wednesday, 22 November 2017 at 15:31:36 UTC, Tim Hsu wrote:
It seems in D, reference has its own address, am I right?
unlike c++
The local variable does have its own address. Do not take its
address - avoid &this or &obje
On Wednesday, 22 November 2017 at 15:31:36 UTC, Tim Hsu wrote:
It seems in D, reference has its own address, am I right?
unlike c++
In case of classes, yes. But I think function parameter
references do not (or rather, of course they have since they
exist in memory but it's hidden). Not sure t
On Wednesday, 22 November 2017 at 15:23:58 UTC, Tim Hsu wrote:
m_window = glfwCreateWindow();
glfwSetWindowUserPointer(m_window, cast(void *)(&this));
That that & out of there!
glfwSetWindowUserPointer(m_window, cast(void *)(this));
without the &, you are fine.
Then, on the other side
On Wednesday, 22 November 2017 at 15:31:36 UTC, Tim Hsu wrote:
It seems in D, reference has its own address, am I right?
unlike c++
The local variable does have its own address. Do not take its
address - avoid &this or &object.
Just cast the ref itself.
In D, a class this or Object variabl
On Wednesday, 22 November 2017 at 15:27:27 UTC, Dukc wrote:
It's worth noting that you will still be passing different
addresses to foo(void*) because classes are reference types in
D (structs are not). In the constructor you're passing the
address of the class object itself, but in the main fu
On Wednesday, 22 November 2017 at 15:27:27 UTC, Dukc wrote:
On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe
wrote:
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch
wrote:
&this will do.
Even if it were an lvalue, that would be the address of a
local. You should basic
On Wednesday, 22 November 2017 at 15:23:58 UTC, Tim Hsu wrote:
I am afraid what will happen when casting this reference to
void *
a ref is a ptr.
The cast will produce a ptr which is valid as long as the ref is
valid.
On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe
wrote:
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch
wrote:
&this will do.
Even if it were an lvalue, that would be the address of a
local. You should basically NEVER do that with D classes.
Just `cast(void*) this`
On Wednesday, 22 November 2017 at 15:17:33 UTC, Adam D. Ruppe
wrote:
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch
wrote:
&this will do.
Even if it were an lvalue, that would be the address of a
local. You should basically NEVER do that with D classes.
Just `cast(void*) this`
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote:
&this will do.
Even if it were an lvalue, that would be the address of a local.
You should basically NEVER do that with D classes.
Just `cast(void*) this` if you must pass it to such a function.
On Wednesday, 22 November 2017 at 15:14:32 UTC, Stefan Koch wrote:
On Wednesday, 22 November 2017 at 15:11:08 UTC, Tim Hsu wrote:
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch
&this will do.
I've tried it in the first place.
...
Error: this is not an lvalue
In that case cas
On Wednesday, 22 November 2017 at 15:11:08 UTC, Tim Hsu wrote:
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch
&this will do.
I've tried it in the first place.
...
Error: this is not an lvalue
In that case casting to void* should be fine.
On Wednesday, 22 November 2017 at 15:07:54 UTC, Stefan Koch wrote:
On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote:
I am a C++ game developer and I want to give it a try.
It seems "this" in Dlang is a reference instead of pointer.
How can I pass it as void *?
void foo(void *);
On Wednesday, 22 November 2017 at 15:07:08 UTC, Tim Hsu wrote:
I am a C++ game developer and I want to give it a try.
It seems "this" in Dlang is a reference instead of pointer.
How can I pass it as void *?
void foo(void *);
class Pizza {
public:
this() {
Pizza newone = this;
I am a C++ game developer and I want to give it a try.
It seems "this" in Dlang is a reference instead of pointer.
How can I pass it as void *?
void foo(void *);
class Pizza {
public:
this() {
Pizza newone = this;
// works but newone is actually not this pizza.
foo(
18 matches
Mail list logo