+ 1

Why i can't pass the parameters?

I want to share the personalInfo() to a derived class and pass the parameters. It keep saying expected identifier error and "," expected before ... Note i'm rookie. https://code.sololearn.com/cNnAMFlpCIL2/?ref=app

28th Apr 2019, 6:46 PM
Mr Thaw
Mr Thaw - avatar
2 Answers
+ 4
Hey there😃 There seem to be multiple errors in your code. Don't worry, I'm here to help 😉 In main(), you seem to be missing a semicolon after `return 0`. Secondly, in your derived class, you're not calling personalInfo. Instead, you are redefining it. To fix it, place that whole line of code (without the `void` keyword) in the constructor of the derived class. --- When we refer to a property in class, we need to use `this` before the assignment. this->var = 5; In your code, you'll need to add `this->` before all the variables in personalInfo: class Parent { public: string name; // Other properties Parent() {} PersonalInfo(string n, int age) { this->name = n; } }; Hope it helps 😃
28th Apr 2019, 7:08 PM
Edwin Pratt
Edwin Pratt - avatar