One of the methods that work 1 within the framework of system rules of imperfect type:
auto main() -> int { using Ten_ints = int [10]; Ten_ints* p_ints = []() -> Ten_ints* { struct Wrapper{ Ten_ints a; }; return &(new Wrapper)->a; }(); (void) p_ints; }
A more direct path, taking responsibility:
auto main() -> int { using Ten_ints = int [10]; Ten_ints* p_ints = reinterpret_cast<Ten_ints*>( new Ten_ints ); (void) p_ints; }
The first fragment does what the OP requested (cited at the end of this answer), using plain new instead of new[] to highlight the object. The second snippet shows the most natural IMO way to use new[] . OP's suggestion for new int[1][10] is the second way to do this (and thus is the third way to get a pointer to an array) and has the advantage of working in a type system, but the disadvantage is that it is not very obvious.
In conclusion, the answer to
" you can use [non-array] new to select a single object of type int[10]
of course.
1 The standard guarantees that there is no padding at the beginning of the POD struct . In practice, this means that release is also not a problem. But for the formal one needs to use the same type for release as for allocation.
Cheers and hth. - alf
source share