#include <iostream>
using namespace std;
class Complex{
public:
Complex(): m_real(0.0), m_image(0.0) {cout << 1 << endl;}
Complex(double real, double image): m_real(real), m_image(image) {cout << 2 << endl;}
Complex(double real): m_real(real), m_image(0.0) {cout << 3 << endl;}
Complex(const Complex &a) {cout << 4 << endl;}
Complex & operator=(const Complex &a) {cout << 5 << endl; return *this;}
private:
double m_real;
double m_image;
};
int main()
{
Complex c1(26.4);
Complex c2 = 240.3; // 结果是3, 很耐人寻味啊,本以为,先是3,然后5或者4的
Complex(15.9);
return 0;
}
构造函数思考
最新推荐文章于 2024-07-09 22:37:42 发布