Apr 29, 2018 at 5:26pm UTC
I have a problem. this code is not compilling. I have to make person class, then
with name and surname, then make Abonememt class, connect to person class and where we get three parameter. But How?
#include <iostream>
using namespace std;
class Person{
protected:
char* Name;
char* SurName;
public:
Person(char *Name, char* SurName){
Set(Name,SurName);
}
void Set(char *Name, char* SurName){
this->Name=Name;
this->SurName=SurName;
}
char *GetName(){
return this->Name;
}
char *GetSurName(){
return this->SurName;
}
};
class Abon:public Person{
protected:
int PhNum;
public:
Abon(char *Name, char *SurName, int PhNum){
Set(Name,SurName,PhNum);
this->PhNum=PhNum;
}
void Set(char *Name, char *SurName){
Person::Set(Name,SurName);
}
};
int main(int argc, char** argv) {
return 0;
}
Apr 29, 2018 at 5:38pm UTC
Ca you please use the tags for code before the code, and
after.
What errors do you get?
Apr 29, 2018 at 5:42pm UTC
[Error] no matching function for call to 'Person::Person()'
error in Abon class, why it calls Person class,
Apr 29, 2018 at 5:46pm UTC
Your set function only takes in 2 parameters, but you are inputing 3 parameters (Name,SurName,PhNum).
Apr 29, 2018 at 5:49pm UTC
oh yes i changed it, but compilator is showing error, Abon constructor line is red
Apr 29, 2018 at 5:51pm UTC
Your Abon cunstroctor should be
Abon(char *Name, char *Surname, int PhNum) : Person(Name, Surname), PhNum(PhNum) {}
Your Person constructor should be:
Person(char *Name, char * SurName) : Name(Name), SurName(SurName) {}
Apr 29, 2018 at 5:55pm UTC
And after that i don't need Set function?
Apr 29, 2018 at 5:57pm UTC
No, that is what your constructor is for :) The setFunction will be used to change those members outside of the class, after they are constructed.
Apr 29, 2018 at 5:58pm UTC
Why do you have char instead of string for name and surname if i may ask?
Apr 29, 2018 at 6:03pm UTC
My teacher told me to use char massive, to learn working on massive in class :D