编程遇到问题,求大虾指点,万分感谢!

#include<iostream>#include<string>usingnamespacestd;classData{public:Data(stringname1... #include<iostream>
#include<string>
using namespace std;
class Data
{
public:
Data(string name1,char sex1,int age1);

virtual ~Data() {}
void print()
{
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"age:"<<age<<endl;
}
protected:
string name;
char sex;
int age;
};
class Student: public Data
{
Student(string name1,char sex1,int age1,string major1,double score1):Data(name1,sex1,age1)
{
major=major1;
score=score1;

}
~Student() {}
void print()
{
Data::print();
cout<<"major:"<<major<<endl;
cout<<"score:"<<score<<endl;
}
protected:
string major;
double score;
};
Data::Data(string name1,char sex1,int age1)
{
name=name1;
sex=sex1;
age=age1;
}
int main()
{
Student mystudent("小明",'m,22,"应用数学”,90);
cout<<"Student:"<<endl;
student.print();
return 0;
}

错误,不懂为什错?
Compiling...
¹ÜÀí.cpp
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(52) : error C2018: unknown character '0xa3'
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(52) : error C2018: unknown character '0xbb'
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(53) : error C2248: 'Student::Student' : cannot access private member declared in class 'Student'
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(24) : see declaration of 'Student::Student'
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(53) : error C2248: 'Student::~Student' : cannot access private member declared in class 'Student'
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(31) : see declaration of 'Student::~Student'
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(53) : error C2146: syntax error : missing ';' before identifier 'cout'
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(54) : error C2065: 'student' : undeclared identifier
D:\Program Files (x86)\Microsoft Visual Studio\MyProjects\Êý¾Ý\¹ÜÀí.cpp(54) : error C2228: left of '.print' must have class/struct/union type
展开
 我来答
德克and德华

2013-03-24 · TA获得超过2650个赞
知道小有建树答主
回答量:1207
采纳率:100%
帮助的人:616万
展开全部
#include<iostream>
#include<string>
using namespace std;
class Data
{
public:
Data(string name1,char sex1,int age1);

virtual ~Data() {}
void print()
{
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
cout<<"age:"<<age<<endl;
}
protected:
string name;
char sex;
int age;
};
class Student: public Data
{
public://加个public,不然你的构造函数是私有的,print函数也是私有的,在main中无法调用
Student(string name1,char sex1,int age1,string major1,double score1):Data(name1,sex1,age1)
{
major=major1;
score=score1;

}
~Student() {}
void print()
{
Data::print();
cout<<"major:"<<major<<endl;
cout<<"score:"<<score<<endl;
}
protected:
string major;
double score;
};
Data::Data(string name1,char sex1,int age1)
{
name=name1;
sex=sex1;
age=age1;
}
int main()
{
Student mystudent("小明",'m',22,"应用数学",90);//你有些符号写成了全角,'m那里又漏了一个引号
cout<<"Student:"<<endl;
mystudent.print();//你写成了student,改成mystudent
return 0;
}
意法半导体(中国)投资有限公司
2023-06-12 广告
单片机汇编程序是用汇编语言编写的程序,用于控制单片机的操作。汇编语言是一种比较接近计算机硬件语言的低级语言,相对于高级语言来说更容易理解和实现。下面是单片机汇编程序的基本步骤:1. 将代码和数据汇编到规定的段中。2. 在存储器中用未初始化的... 点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
lyhdez1
2013-03-24 · TA获得超过1942个赞
知道小有建树答主
回答量:687
采纳率:100%
帮助的人:834万
展开全部
构造函数前面少了public:
Student mystudent("小明",'m,22,"应用数学”,90);这一行90前面的逗号输入法有问题,改为英文输入的逗号
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式