首页 新闻 会员 周边

求高人帮我看看下面这段代码啊

0
悬赏园豆:5 [已解决问题] 解决于 2016-04-04 14:38
#include<iostream>
#include<string>
using namespace std;
class student
{
public:
    student(float number1, string name1, float score1)
    {
        number = number1;
        name = name1;
        score = score1;
    }
    void print()
    {
        cout << "number:" << number << endl;
        cout << "name:" << name << endl;
        cout << "score:" << score << endl;
    }
protected :
    float number;
    string name;
    float score;
};
class USstudent :public student
{
    USstudent(float number1, string name1, float score1, string major1) 
        :student(number1, name1, score1)
    {
        major = major1;
    }
    void print()
    {
        student::print();
        cout << "major:" << major << endl;
    }
private :
    string major;
};
int main()
{
    USstudent stu(22116, "chih", 89,"computer science" );
    stu.print();
    return 0;
}

编译器提示在主函数实参22116那个地方有错,还有stu.print()也有错。

爱是用心码不要说话的主页 爱是用心码不要说话 | 初学一级 | 园豆:154
提问于:2016-04-03 22:28
< >
分享
最佳答案
1

你的print和构造函数都没有加上访问权限修饰符,在C++中默认的是private,所以编译器就会报错,加上public修饰符就好了

收获园豆:5
Iltxy | 菜鸟二级 |园豆:209 | 2016-04-04 09:26

多谢帮助,明白了

爱是用心码不要说话 | 园豆:154 (初学一级) | 2016-04-04 14:38
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册