Assigning the return value of new by reference is deprecated

A nice and specific question!

In C++, the new operator returns a pointer to the newly created object. When you assign the result of new to a reference, it's not actually assigning the reference to the object, but rather creating a temporary reference that points to the object.

This behavior is deprecated in C++17 and later, because it can lead to unexpected behavior and is generally considered a bad practice.

Here's an example of what I mean:

int* p = new int(5);
int& r = p; // deprecated

In this example, r is a reference to the pointer p, not to the object created by new. This can lead to confusion and bugs, especially when working with smart pointers or other complex memory management scenarios.

To avoid this deprecation warning, you can simply assign the result of new to a pointer, like this:

int* p = new int(5);

Alternatively, you can use smart pointers like unique_ptr or shared_ptr, which automatically manage the memory and don't require manual pointer manipulation.

So, to summarize: assigning the return value of new by reference is deprecated in C++17 and later, and you should avoid doing so to ensure your code is safe and maintainable.