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 = " ";
    }
5
  • cant you assign it with something like Date birthdate = Date(0,0,0) ? Commented Feb 17, 2018 at 1:39
  • Use the Member 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. minimal reproducible example required for more specific information. Commented Feb 17, 2018 at 1: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. Commented Feb 17, 2018 at 1:47
  • Duplicate-ish: How can I initialize C++ object member variables in the constructor? Commented Feb 17, 2018 at 1:53
  • @Hannah but its ok to have it be Date birthDate() = 0 what do you want to be there? Commented Feb 17, 2018 at 2:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.