(表示一個二元運算符),a ? b 的操作會被解釋為下面2種形式之一
? b a.(b); (a, b);
#include <iostream> (Default constructor) ComplexA(){cout<<<<(The constructor with parameters) ComplexA( re, im):real(re),image(im){cout<<<<(Copy constructor) ComplexA( ComplexA& ){real = .real; image = .image; cout<<<<(destructor) ~ComplexA(){cout<<<< ComplexA +(ComplexA& ComplexA(real + .real, image + ComplexA -(ComplexA& ComplexA(real - .real, image - ComplexA *(ComplexA& ComplexA(real * .real, image * ComplexA /(ComplexA& ComplexA(real / .real, image / display(){cout<<real<<<<image<<<< real; image; (Default constructor) ComplexB(){cout<<<<(The constructor with parameters) ComplexB( re, im):real(re),image(im){cout<<<<(Copy constructor) ComplexB( ComplexB& ){real = .real; image = .image; cout<<<<(destructor) ~ComplexB(){cout<<<< friend ComplexB +(ComplexB& ref1, ComplexB& ComplexB(ref1.real + ref2.real, ref1.image + friend ComplexB -(ComplexB& ref1, ComplexB& ComplexB(ref1.real - ref2.real, ref1.image - friend ComplexB *(ComplexB& ref1, ComplexB& ComplexB(ref1.real * ref2.real, ref1.image * friend ComplexB /(ComplexB& ref1, ComplexB& ComplexB(ref1.real / ref2.real, ref1.image / display(){cout<<real<<<<image<<<< real; image; (Default constructor) ComplexC(){cout<<<<(The constructor with parameters) ComplexC( re, im):real(re),image(im){cout<<<<(Copy constructor) ComplexC( ComplexC& ){real = .real; image = .image; cout<<<<(destructor) ~ComplexC(){cout<<<< GetReal(){ GetImage(){
display(){cout<<real<<<<image<<<< real; image; ComplexC +(ComplexC& ref1, ComplexC& ComplexC(ref1.GetReal() + ref2.GetReal(), ref1.GetImage() + ComplexC -(ComplexC& ref1, ComplexC& ComplexC(ref1.GetReal() - ref2.GetReal(), ref1.GetImage() - ComplexC *(ComplexC& ref1, ComplexC& ComplexC(ref1.GetReal() * ref2.GetReal(), ref1.GetImage() * ComplexC /(ComplexC& ref1, ComplexC& ComplexC(ref1.GetReal() / ref2.GetReal(), ref1.GetImage() / main(,), C2(, = C1 += C1 -= C1 *= C1 /<<<<,), C5(, = C4 += C4 -= C4 *= C4 /<<<<,), C8(, = C7 += C7 -= C7 *= C7 /
,或者反過來 ,這時上面的程序的重載方式就不適用了。
#include <iostream> re = , im = +(ComplexD& ){ ComplexD(real+.real, image++( a){cout<<; ComplexD(real++( d){cout<<; ComplexD(real++( f){cout<<; ComplexD(real+ display(){cout<<real<<<<image<<<< GetReal(){ GetImage(){+( a, ComplexD& ){cout<<; ComplexD(.GetReal()+a, +( d, ComplexD& ){cout<<; ComplexD(.GetReal()+d, +( f, ComplexD& ){cout<<; ComplexD(.GetReal()+f, main(,= D1 + = D1 + = D1 + = += += +