It's generally not a good idea to use raw pointers and new
directly.
The less of that, the better.
Instead, to create your array on the heap, do this:
std::vector<Cat> cats( 2 );
for( int i = 0; i < int( cats.size() ); ++i ){
cats[i].age = i+1;
}
or alternatively, this:
std::vector<Cat> cats;
for( int i = 0; i < 2; ++i ){
cats.emplace_back( i+1 );
}
The direct use of raw arrays and new
indicates a C programmer or incompetent, since std::vector
is in the C++ standard library precisely for this purpose, taking care of correct memory management.
Note also that ALL UPPERCASE names are a convention used for macros. The idea is to minimize the chance of name collisions and inadvertent text substitution. When you use such names for other things, you instead increase the chance of name collisions and inadvertent text substitution, not to mention that many programmers read all uppercase as shouting, extra strong emphasis.