首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

指针重载的疑惑,c++ bug?解决思路

2012-03-05 
指针重载的疑惑,c++ bug?#includestring#includeiostreamusingnamespacestdclassToken{public:Token(

指针重载的疑惑,c++ bug?
#include   <string>
#include   <iostream>
using   namespace   std;

class   Token
{
public:
        Token()
        {}
        const   string&   s_text()
        {
                cout   < <   "ok! "   < <   endl;
                return   text;
        }
        string   text;
};


class   Pointer
{
public:
        Pointer(){sn=0;}
        typedef   Token*                       pointer_type;
        pointer_type   operator   -> ()   const
        {
                cout   < <   "pointer   value= "   < <   (int)   sn   < <   endl;
                return     (   pointer_type   )sn;//sn==0
        }
        Token*   sn;
};


int   main()
{
        Pointer   pp;
        pp-> s_text();//为什么   sn==0   却仍可以调用s_text()不报错
        return   0;
}
程序输出
pointer   value=0
ok!

[解决办法]
看这个帖子, 说得很清楚了!
http://community.csdn.net/Expert/topic/5526/5526033.xml?temp=.2860224

热点排行