#include<iostream>
#include<cstring>
using namespace std;
class student
{
public:
student(int n,string nam)
{
num=n;
name=nam;
}
void display()
{
cout<<num<<endl;
cout<<name<<endl;
}
protected:
int num;
string name;
};
class student1:public student
{
public:
student1(int n,string nam,int a):student(n,nam)
{
age=a;
}
void show()
{
display();
cout<<age<<endl;
}
private:
int age;
};
class student2:public student1
{
public:
student2(int n,char nam[10],int a,int s):student1(n,nam,a) /*这里char nam[10]与string nam不匹配,导致程序出错,应将char nam[10]改为string nam ,就可以啦!注意相互匹配,这是基础问题*/
{
score=s;
}
void show_all()
{
show();
cout<<score<<endl;
}
private:
int score;
};
int main()
{
student2 stud(10010,"Li",17,89);
stud.show_all();
return 0;
}
(无法调用相匹配函数)[Error] no matching function for call to ‘student1::student1(int&, std::stri
于 2023-01-26 15:15:28 首次发布