0

I'm creating a default constructor for a struct and setting all values to 0, but there is a substruct and value (Date birthDate) referenced and I'm not sure how to handle it.

The Date struct includes 3 integers: day, month, year. Combined they = birthDate.

Reptile::Reptile(){
    species = " ";
    DangerAssessment dangerAssess = "";
    Date birthDate() = 0;
    SizeOfEnclosure sizeofenclosure;
    exhibitName = " ";
    }
Hannah
  • 1
  • 1
  • cant you assign it with something like `Date birthdate = Date(0,0,0)` ? – AntiMatterDynamite Feb 17 '18 at 01:39
  • [Use the Member initializer list.](http://en.cppreference.com/w/cpp/language/initializer_list). Should look something like `Reptile::Reptile(): species(""), dangerAssess(""), birthDate(0), sizeofenclosure(0), exhibitName("") { }` If you are calling default constructors you can leave them out. They will be default constructed. [mcve] required for more specific information. – user4581301 Feb 17 '18 at 01:41
  • @AntiMatterDynamite I'm afraid not. That would make and initialize an Automatic variable scoped to only exist within the body of the constructor. It would not initialize or assign a member variable. – user4581301 Feb 17 '18 at 01:47
  • Duplicate-ish: [How can I initialize C++ object member variables in the constructor?](https://stackoverflow.com/questions/12927169/how-can-i-initialize-c-object-member-variables-in-the-constructor) – user4581301 Feb 17 '18 at 01:53
  • @Hannah but its ok to have it be `Date birthDate() = 0` what do you want to be there? – AntiMatterDynamite Feb 17 '18 at 02:09

0 Answers0