| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 499 人关注过本帖
标题:&的运算符的原理到底是什么
只看楼主 加入收藏
换空依晨
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2013-9-13
结帖率:30.77%
收藏
 问题点数:0 回复次数:4 
&的运算符的原理到底是什么
程序代码:
#include"iostream.h"
class point
{
private:
    int x,y;
public :
    point (int xx=0,int yy=0)
    {
    x=xx;
    y=yy;
    }
    int getx()
    {
        return x;
    }
    int gety()
    {return y;}
    friend point operator++(point &P);
};
point operator++(point &p)
{
++p.x ;
++p.y ;return p;
}
void main()
{
point ob(3,4);
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
++ob;
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
operator++(ob);
cout<<"ob.x="<<ob.getx()<<" ob.y="<<ob.gety()<<endl;
}
point operator++(point &p) 里面的&的具体作用是什么 怎么取址的  如果把&去掉 为什么不能实现自增啊 麻烦大家把原理讲的详细点
搜索更多相关主题的帖子: return 
2014-02-27 09:37
peach5460
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:武汉
等 级:贵宾
威 望:30
帖 子:2780
专家分:6060
注 册:2008-1-28
收藏
得分:0 
麻烦看书看仔细一点...
&是传引用...

我总觉得授人以鱼不如授人以渔...
可是总有些SB叫嚣着:要么给代码给答案,要么滚蛋...
虽然我知道不要跟SB一般见识,但是我真的没修炼到宠辱不惊...
2014-02-27 09:40
fl8962
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:14
帖 子:539
专家分:2471
注 册:2012-10-17
收藏
得分:0 
回复 楼主 换空依晨
if you do not put & before the variable, when the function outside the main function ends, the address of the variable will be set free. So, there will be no change for your variable inside the main function, but if you put & before, the function outside gets the address rather the value. So the variable will be changed.

....
bu hao yi si, xue xiao de dian nao, mei you zhong wen shu ru.

想抽苏烟了。
2014-02-28 01:31
zklhp
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:china
等 级:贵宾
威 望:254
帖 子:11485
专家分:33241
注 册:2007-7-10
收藏
得分:0 
有的时候应用就是用指针实现的 如果你非要问原理的话

这个是以前他们逆向知道的、、、
2014-03-01 20:43
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
收藏
得分:0 
誰告訴你這個是取址?

授人以渔,不授人以鱼。
2014-03-01 22:35
快速回复:&的运算符的原理到底是什么
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018678 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved