I\'m working on an example program to help me learn structs in C++. Here\'s my code:
#include
#include
#include
The problem has not to do with a "default-construct ... when class person does not have a default constructor." The problem has to do with having a constant in the declaration of the class and a constructor that does not guarantee that the constant will be defined. Suggest using an "initializer list".
struct Person {
int id;
string name;
date birthdate;
const int numberOfAddresses;
address addresses [1];
Person(int); // constructor declaration
Person() : numberOfAddresses(1) {} // constructor definition.
// ": numberOfAddresses(1)" is the initializer list
// ": numberOfAddresses(1) {}" is the function body
};
Person::Person(int x) : numberOfAddresses(x) {} // constructor definition. ": numberOfAddresses{x}" is the initializer list
int main()
{
Person Bob; // calls Person::Person()
Person Shurunkle(10); // calls Person::Person(int)
}