Friday, 15 June 2012

inheritance - initialise string array or 2d char array in derived class in c++ -



inheritance - initialise string array or 2d char array in derived class in c++ -

here's snippet:

class pupil { protected: string name, subject[6]; .... }; class ugstudent : public pupil { ... }; class ugfirst_yr : public ugstudent { subject[6] = {"phy", "chem", "math", "electrical", "civil", "comp"}; //error* public: ... };

*the errors above initialization: "this declaration has no storage class or type specifier", , contents in array: value of type "const char *" cannot used initialize entity of type "int"

what want string array subject[] common, contents of array should differ in each class derived class ugstudent. should change?

try this

class pupil { public: vector<string> subject; student() : subject{ "a", "b", "c" } { } };

c++ inheritance arrays

No comments:

Post a Comment