operator short () const;

pan2008 2003-08-22 09:15:43
这个怎么理解
operator short () const;
...全文
42 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixue3000 2003-08-22
  • 打赏
  • 举报
回复
here is a test:
class A
{
public:
char c;
operator short ()const{return c;}
};


int main(int argc, char *argv[])
{
A a1,a2;
a1.c = 'd';
a2.c = 'G';
cout << a1.c << a2.c << endl;;
short s1 = a1;
cout << s1 << endl;;
s1 += a2;
cout << s1 << endl;;
system("PAUSE");
return 0;
}
feixue3000 2003-08-22
  • 打赏
  • 举报
回复
重载short关键字,const代表本函数不会修改任何数值。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧