What does it mean when I use new auto
? Consider the expression:
new auto(5)
What is the type of the dynamically allocated object? What is the type of the pointer it returns?
What does it mean when I use new auto
? Consider the expression:
new auto(5)
What is the type of the dynamically allocated object? What is the type of the pointer it returns?
In this context,
auto(5)
resolves toint(5)
.You are allocating a new
int
from the heap, initialized to5
.(So, it's returning an
int *
)Quoting Andy Prowl's resourceful answer, with permission:
Per Paragraph 5.3.4/2 of the C++11 Standard:
Per Paragraph 5.3.4/2 of the C++11 Standard:
Therefore, the type of the allocated object is identical to the deduced type of the invented declaration:
Which is
int
.