Re: Does new X() return a pointer or not?

2019-04-06 Thread faissaloo via Digitalmars-d-learn

Thanks alot everyone for your replies, this makes sense now.


Re: Does new X() return a pointer or not?

2019-04-06 Thread Adam D. Ruppe via Digitalmars-d-learn

On Saturday, 6 April 2019 at 13:34:06 UTC, faissaloo wrote:

ComponentChild is a derived class of Component.


This means it is not a Component*.

new X returns a pointer if X is a struct, but for classes, it is 
not.



Are objects automatically assumed to be pointers?


Yeah, for classes.




Re: Does new X() return a pointer or not?

2019-04-06 Thread rikki cattermole via Digitalmars-d-learn

On 07/04/2019 2:34 AM, faissaloo wrote:

Are objects automatically assumed to be pointers?


It is a reference. Which is a fancy way of saying pointer under the hood.

Just don't do pointer arithmetic with it ;)

Object* means a pointer to a class object reference. Which isn't what 
you were intending.

int* means a pointer to a 4-byte signed integer.

Does that make sense?


Does new X() return a pointer or not?

2019-04-06 Thread faissaloo via Digitalmars-d-learn

I have the following function

static Component* constructComponent(int value) {
return (new ComponentChild(value));
}

ComponentChild is a derived class of Component.
However, I get told that ComponentChild cannot be converted to 
Component*. I'm confused here, does new return a heap pointer or 
not? Are objects automatically assumed to be pointers?