c++之学习程序继承public
来源:互联网 发布:18亿亩耕地红线 知乎 编辑:程序博客网 时间:2024/05/22 01:55
我没有按书上的原意写的,还是重载了输出,可提示的错误我不知道怎么改。
#include<iostream.h>
class Student1
{
public:
void get_value()
{
cin>>num>>name>>sex;
}
friend ostream& operator<<(ostream &out,Student1 &stud)
{
out<<"number:/n"<<stud.num<<"name:/n"<<stud.name<<"sex:/n"<<stud.sex<<endl;
return out;
}
private:
int num;
char name[20];
char sex;
};
/*ostream& operator<<(ostream &out,Student1 &stud)
{
out<<"number:/n"<<stud.num<<"name:/n"<<stud.name<<"sex:/n"<<stud.sex<<endl;
return out;
}*/
class Student2:public Student1
{
public:
void get_value_1()
{
get_value();
cin>>age>>addr;
cout<<endl;
}
friend ostream& operator<<(ostream&,Student2)
{
out<<"age:/n"<<stud.age<<"addr:/n"<<stud.addr;
return out;
}
protect:
int age;
char addr[30];
};
/*ostream& operator<<(ostream &out,Student2 &stud)
{
out<<"age:/n"<<stud.age<<"addr:/n"<<stud.addr;
return out;
}*/
int main()
{
Student2 stud;
cout<<"input the Student's number,name,sex,age,addr:/n";
stud.get_value_1();
cout<<stud;
return 0;
}
Compiling...
public.cpp
C:/Program Files/Microsoft Visual Studio/MyProjects/2010/public.cpp(40) : error C2062: type 'char' unexpected
C:/Program Files/Microsoft Visual Studio/MyProjects/2010/public.cpp(40) : error C2238: unexpected token(s) preceding ';'
Error executing cl.exe.
public.obj - 2 error(s), 0 warning(s)
- c++之学习程序继承public
- c++之学习程序继承public(修改)
- C/C++:public公有继承
- C++:public继承、protected 继承、private继承
- C++:public继承、protected 继承、private继承
- C++:private继承与public继承
- C++:private继承与public继承
- C++:private继承与public继承
- public、protect、private继承方式 C++(转)
- 《Effective C++》学习笔记条款32 确定你的public继承塑模出is-a关系
- 《Effective C++》读书笔记之item32:确定你的public继承塑模出is-a关系
- C++之确定你的public继承塑模出is-a关系(32)---《Effective C++》
- PUBLIC 继承
- public继承
- Object-C: 学习实例之继承
- C++学习笔记11,public继承,公有继承(二)
- C++中的公有继承(public)问题
- 继承 Objective-C中public、protected、private的使用
- 关于运行msdn 2001时出现“打不开MSDNxxx.COL”的提示与搜索项无显示
- SharePoint designer中图片缩小后变模糊的处理
- 计数排序;非比较排序法;时间复杂度接近于O(n);
- 纪念谷歌被和谐事件
- Crash Dump Analysis
- c++之学习程序继承public
- 开源和混淆
- 远程桌面/远程登陆中强行登陆(他人退出)与切换回话(登陆后切换到上次别的登陆)
- ACM常用基础(二)常用函数
- 不得不知的60个生活小秘方
- im2col - Rearrange image blocks into columns
- 总杂
- gtk+2.0 开发的一个对话框
- 雨林木风Ghost XP Sp3 YN14.5 IIS安装