Setting Name[SIZE]
to point to the address of std::string *
is meaningless.
If Name
is a std::string array, then the array will be defaulted empty.
If your task was to set the Name
field empty in the constructor, I'm going to assume this is a const char* instead of a std::string. This can be done using initializer list:
Horse::Horse()
: Name{0} // Name{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} does the same thing.
{} // empty body
The above will initialize all the 20 positions to 0, or NULL if you like. Just as if you declared it in the global scope.
If you are not familiar with the initializer list in constructors, you can always do this, but at an extra cost:
Horse::Horse() // Initialize members runs first
{
for (int i = 0; i != SIZE; ++i) // Assign values to Name array
Name[i] = 0;
}
Side note: Instead of using macros to define your values,
a better choice is to use const unsigned SIZE = 20;
for reasons described here