+ 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
2 ответов
+ 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 😃