The variable by default in class is public in Private,struct, the other two are similar, you can have a constructor destructor, or you can inherit. #include <iostream>using namespace std;enum breed {golden,cairn,dandie,shetland ,doberman,lab};struct mammal{ public: mammal (): Itsage (2), Itsweight (5) {} ~mammal () {} int getage () const {return itsage;} void setage (Int age) {itsAge = age;} int getweight () const {return itsweight;} void setweight (int weight) {itsWeight = weight;} void speak () const {cout<< "\nmammal Sound! ";} void  Sleep () const {cout<< "\nshhh.i ' m sleeping.";} protected: int itsAgel; int itsWeight; }; struct Dog:public Mammal{ Public: dog (): Itsbreed (GOLDEN) {} ~dog () {} breed getbreed () const {return itsbreed;} void setbreed (breed breed) {itsBread = breed;} void wagtail () const {cout<< "tail Wagging...\n ";} void begforfood () const {cout<< "begging for&nbSp;food...\n ";} private: BREED itsBreed; };int main () { dog fido; fido. Speak (); fido. Wagtail (); cout<< "Fido is" <<fido. Getage () << "years old \n"; return 0; }
The difference between struct and class