I want to ask you why those two 'Student' constructor commented below don't work.
#include<iostream>
#include<string>
using namespace std;
class Temp{
public:
void Tempshow(){
cout << "Mother Class" << endl;
}
};
class Person{
private:
string name;
public:
Person(string name): name(name){} //member initialization
string getName(){
return name;
}
void showName(){
cout << "Name : " << getName() << endl;
}
};
class Student : Person, public Temp {
private:
int studentID;
public:
Student(int studentID, string name) : Person(name){
this->studentID = studentID;
}
// Student(int studentID, string name){
// Person(name);
// this->studentID = studentID;
// }
// Student(int studentID, string name){
// this->studentID = studentID;
// }
void show(){
cout << "Student Number : " << studentID << endl;
cout << "Student Name : " << getName() << endl;
}
void showName(){
cout << "Inherent Success : " << getName() << endl;
}
};
int main(){
Student student = Student(1, "James");
student.showName();
student.Tempshow();
return 0;
}
In addition I want to ask...
Student(int studentID, string name) : Person(name){
this->studentID = studentID;
}
inside the arguments of 'Student' constructor in this sentence, are 'studentID 'and 'name' just arguments and just do works in the scope of 'Student' constructor? Or 'studentID 'and 'name' are the member variables of 'Student' class and 'Person' class?
I don't have idea how this sentence can give argument to the 'Person' constructor
Student student = Student(1, "James");