c++ student2::student2(const student2 &): 不能将参数 1 从“int”转换为“const student2 &”错在哪?

2025-01-07 02:37:45
推荐回答(1个)
回答1:

#include
#include
using namespace std;
class student 
{
public:
    student(int a,string b):num(a),name(b){ }
    void display()
    {cout<<"num:"<    cout<<"name:"<private:
  int num;
  string name; 
};
class student1:public student
{public:
student1(int a,string b,int c):student(a,b){age=c;}
void show()
{  display();
cout<<"age:"<private:
int age;
};
class student2:public student1
{
public:
    student2(int a,string b,int c,int d):student1(a,b,c){score=d;}
    void show_all()
    {
    show();
    cout<<"score:"<    }
private:
    int score;
}; //这里少了一个分号
int main()
{
 student2 stu(1,"hehe",22,100);
 stu.show_all();
 return 0;
}