看下面一段程序:
#include <iostream.h>
class a
{
public :
void print() const {cout <<"a::print() called\n" ;};
};class b :public a
{
public :
void f(){} ;
void printf() {cout <<"b::printf() called\n" ;};
};void f1(const a& r)
{
r.print() ;
};void main()
{
b b1 ;
f1(b1) ;
return ;
};
请问:
程序输出结果是什么.
对于void print() const {cout <<"a::print() called\n" ;}; 这段程序中的const 看不明白..请各位高手讲解讲解........讲解明确者,马上结贴,所有分只送一个人.
#include <iostream.h>
class a
{
public :
void print() const {cout <<"a::print() called\n" ;};
};class b :public a
{
public :
void f(){} ;
void printf() {cout <<"b::printf() called\n" ;};
};void f1(const a& r)
{
r.print() ;
};void main()
{
b b1 ;
f1(b1) ;
return ;
};
请问:
程序输出结果是什么.
对于void print() const {cout <<"a::print() called\n" ;}; 这段程序中的const 看不明白..请各位高手讲解讲解........讲解明确者,马上结贴,所有分只送一个人.
解决方案 »
- tcp发出的数据找不到了
- 多个时间点的定时问题,Timer可以做到吗?
- 建了多文档项目,要打开文本编辑, 和图形显示, 该如何作啊, 请指教啊!
- 小妹学VC求vc6.0的视频教程
- 哪位有p2p(可以穿透防火墙)视频聊天软件的源码
- 窗口style问题请教大家
- 用ADO进行数据库访问,RECORDSET的问题
- 这个问题想必没有人会!不信请进来看!
- 如何在基于dialog的对话框里实现一个线程?
- 按照网络上的方法来绘制图形,怎么会全是黑的呢!怎么也看不到!
- 问题应该不难,但让我这个新手抓耳挠腮!!!全局变量怎么在哪声明??
- 急,邮件发送问题:550 not match the MX Filter Rule(JcAI88kxOKIafKoc.error)
print()为void型,const应该没什么用途吧.
void print() const {cout <<"a::print() called\n" ;};
是:
const成员函数,只有const成员函数才能访问const对象,当然const成员函数特不能修改const对象的
在写程序过程,最好把const对象所要使用的所有成员函数都声明为const.详细情况可以参考
H.M.Deitel和P.J.Deitel父子写的<<c++程序教程>>第三章.
结果是:a::print() called
void print() const "const"在此处作用不大,这样写是为了类的成员函数能够访问私有定义的常量