Chinaunix首页 | 论坛 | 博客
  • 博客访问: 196565
  • 博文数量: 67
  • 博客积分: 2720
  • 博客等级: 少校
  • 技术积分: 625
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-05 13:53
文章分类
文章存档

2011年(1)

2010年(43)

2009年(23)

我的朋友

分类: C/C++

2010-06-21 16:15:17


找错。

#include 
using namespace std;
 
class P
{
public:
    void print()
    {
        cout << "P";
    }
};
 
void print(const P&p)
{
    p.print(); 
}
 
int main()
{
    P p;
    print(p);

    return 0;
}

const P&p将p转换成了P类对象的const引用,而const引用只能调用const成员函数,P的print函数为非const成员函数,故编译出错
阅读(1128) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~