注册 登录
编程论坛 C++教室

&的运算符的原理到底是什么

换空依晨 发布于 2014-02-27 09:37, 505 次点击
程序代码:
#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) 里面的&的具体作用是什么 怎么取址的  如果把&去掉 为什么不能实现自增啊 麻烦大家把原理讲的详细点
4 回复
#2
peach54602014-02-27 09:40
麻烦看书看仔细一点...
&是传引用...
#3
fl89622014-02-28 01:31
回复 楼主 换空依晨
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.
#4
zklhp2014-03-01 20:43
有的时候应用就是用指针实现的 如果你非要问原理的话

这个是以前他们逆向知道的、、、
#5
TonyDeng2014-03-01 22:35
誰告訴你這個是取址?
1