我有这个代码:
#include <iostream>
using namespace std;
class complex
{
double re;
double im;
public:
complex(): re(0), im(0) {}
complex(double x) {re = x, im = x;}
complex(double x, double y) {re=x, im =y;}
void print() {cout << re << " " << im;}
};
int main()
{
complex c1;
double i=2;
c1 = i;
c1.print();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么这一行中的代码会编译。
c1 = i;
Run Code Online (Sandbox Code Playgroud)
编译器没有给出错误(或警告),为什么?
c++ ×1