总是出现这样的错误,在vc6.0里运行的,error C2236: unexpected 'class' 'Student1'
#include<iostream.h>#include<string>usingnamespacestd;classStudent{public:Student(int...
#include<iostream.h>
#include<string>
using namespace std;
class Student
{
public:
Student(int n,string nam)
{
num=n;
name=nam;
}
void display()
{
cout<<"num:"<<num<<endl<<"name:"<<name<<endl;
}
protected:
int num;
string name;
}
class Student1: public Student
{
public:
Student1(int n,string nam,int n1,string nam1,int a,string ad):
Student(n,nam),monitor(n1,nam1)
{
age=a;
addr=ad;
}
void show()
{
cout<<"This student is:"<<endl;
display();
cout<<"age:"<<age<<endl;
cout<<"addr:"<<addr<<endl;
}
void show_monitor()
{
cout<<endl<<"Class monitor is:"<<endl;
monitor.display();
}
private:
Student monitor;
int age;
string addr;
};
int main()
{
Student1 stud1(10010,"wang-li",10001,"Li-sun",19,"115 Beijing Road ,Shanghai");
stud1.show();
stud1.show_monitor();
return 0;
} 展开
#include<string>
using namespace std;
class Student
{
public:
Student(int n,string nam)
{
num=n;
name=nam;
}
void display()
{
cout<<"num:"<<num<<endl<<"name:"<<name<<endl;
}
protected:
int num;
string name;
}
class Student1: public Student
{
public:
Student1(int n,string nam,int n1,string nam1,int a,string ad):
Student(n,nam),monitor(n1,nam1)
{
age=a;
addr=ad;
}
void show()
{
cout<<"This student is:"<<endl;
display();
cout<<"age:"<<age<<endl;
cout<<"addr:"<<addr<<endl;
}
void show_monitor()
{
cout<<endl<<"Class monitor is:"<<endl;
monitor.display();
}
private:
Student monitor;
int age;
string addr;
};
int main()
{
Student1 stud1(10010,"wang-li",10001,"Li-sun",19,"115 Beijing Road ,Shanghai");
stud1.show();
stud1.show_monitor();
return 0;
} 展开
展开全部
class Student
{
public:
Student(int n,string nam)
{
num=n;
name=nam;
}
void display()
{
cout<<"num:"<<num<<endl<<"name:"<<name<<endl;
}
protected:
int num;
string name;
};//这里少了一个分号
Student类的最后少了一个分号
此外头文件引用,别用iostream.h,会报错。
改成#include<iostream>
{
public:
Student(int n,string nam)
{
num=n;
name=nam;
}
void display()
{
cout<<"num:"<<num<<endl<<"name:"<<name<<endl;
}
protected:
int num;
string name;
};//这里少了一个分号
Student类的最后少了一个分号
此外头文件引用,别用iostream.h,会报错。
改成#include<iostream>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询