关于 operator = 运算符重载的疑问? 你的意思是重载int 类的=运算? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 crazy_ax():我不知道是不是这样,只要能实现我的功能就行。 事实上这是强制类型转换啊, x= (int) a 不是重载=的问题了,是重载int 不知道如何重载c++语言内建类别的运算,可以试试下面的方法:#include <iostream>using namespace std;class A{private: int age;public: int operator() () { return age;} };void main(){ A a; a.age=10; int x=a; cout<<"x="<<x<<endl;}希望对你有帮助! 对不起,错了int x=a;==>int x=a(); 可以這樣寫.class CAge{public: operator int() const; const CAge& operator =(int age); private: int m_iAge;};int main(){ CAge cAge; int iAge; cAge = 10; iAge = cAge; return 1;}const CAge& CAge::operator=(int age){ m_iAge = age; return *this;}CAge::operator int()const{ return m_iAge;} 鼠标点击正方形,获取信息 MFC下如何获得本机MAC地址,为什么在mfc下找不到NCB结构啊!!需要什么支持?? 哪为大哥会winsnmp!!! 高手请进→磁性窗体和窗体的同时移动 哪里有基于Windows平台的SNMP协议的网管软件源代码例子,谢谢!!! 请问各位vc高手 请问如何显示16位灰度图像 散分兼分享新版iocpframeowork vc6如何调用VS2005 C#写的DLL?急问 68分求解!!!!!!!如何获取网上文件的大小?如一个Zip文件的大小。 怎样通过LAN中的共享计算机名字得到他的IP或MAC地址,操作系统! VC新手不知如何入门 “HOLLO World!”
#include <iostream>
using namespace std;
class A
{
private:
int age;
public:
int operator() () { return age;}
};
void main()
{
A a;
a.age=10;
int x=a;
cout<<"x="<<x<<endl;
}希望对你有帮助!
int x=a;==>int x=a();
{
public:
operator int() const;
const CAge& operator =(int age);
private:
int m_iAge;
};int main()
{
CAge cAge;
int iAge; cAge = 10; iAge = cAge; return 1;
}const CAge& CAge::operator=(int age)
{
m_iAge = age;
return *this;
}CAge::operator int()const
{
return m_iAge;
}