标签:rgba color space 强制 mes 运算符 this 类型 rgb
namespace D{ class cnum{ public: double Val; cnum(double n): Val(n){ } operator double() { return this->Val; } }; class num{ public: double Val; num(double n): Val(n) { } // 重载强制类型运算符 operator int(){ return this->Val; } operator double() { return this->Val; } operator cnum(){ cnum c(this->Val); cout<<"进入 class num的cnum转换...."<<endl; return c; } }; class bnum{ public: double Val; bnum(double n): Val(n) { } operator num(){ num n(this->Val); return n; } }; void dmain(){ num n1(11.66); double d1 = double(n1); int i1 = (int)n1; cout << &d1 << "\t" << d1 << endl; cout << &i1 << "\t" << i1 << endl; bnum b1(10.88); n1 = num(b1); cout << b1.Val << "\t" << &b1.Val << endl; cout << n1.Val << "\t" << &n1.Val << endl; cnum c1(8.66); //c1 =n1.operator cnum(); 调用成功 这种事显示调用,最安全 c1=n1;//调用成功,这种也会转换成上面那种 cout << c1.Val << "\t" << &c1.Val << endl; } }
标签:rgba color space 强制 mes 运算符 this 类型 rgb
原文地址:https://www.cnblogs.com/jhzou/p/14865744.html