S
S
Sergey Ivchenko2015-10-22 21:51:18
C++ / C#
Sergey Ivchenko, 2015-10-22 21:51:18

When to use pointers to objects when declaring in C++?

I'm starting to learn C++ programming. Tell me, please, when to use : when declaring an object
Object obj();,
and when
Object obj = new Object();
?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2015-10-22
@Serg89

1. A method is a variable created on the stack.
2. This is a variable created in dynamic memory. Unless, of course, you or "your friend" did nothing with the new operator.
Heap memory is much larger than the stack area

V
Vladimir Martyanov, 2015-10-22
@vilgeforce

Only all the same Object* obj = new, as it seems to me.
Using new allows you to create entities while the program is running.

V
Vitaly, 2015-10-22
@vt4a2h

On creation, not on declaration. So far, you always have the first option (but without parentheses). Understand the language and understand.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question