0

Hello, I'm new to C++ with a fair experience in java.

I would like to know the difference between

Ob o* = new Ob();

and

Ob o = new Ob();

I know the first allocates a block of memory and creates a pointer which keeps the address of this block.

What about the second object initialization?

Thank you

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by NathanOliver
0

The second is invalid. Only a pointer to can use the new operator. Here is a little breakdown for you.

int foo = 10;  // normal assignment;
int *fooPointer = new int;
*fooPointer = foo;  // now fooPointer is a pointer to an int that holds the value of 10
int & fooReference = foo;  // reference.  now anything that happens to fooReference happens to foo.

Edited by NathanOliver: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.