初学C语言时,如何理解05版本的运算符重载?

2026-05-05 16:511阅读0评论SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计3159个文字,预计阅读时间需要13分钟。

初学C语言时,如何理解05版本的运算符重载?

运算符重载允许一个函数名拥有多种功能,在特定情况下执行不同操作。运算符重载(Operator Overloading)也是一个理解,同一个运算符可以有不同的行为。

运算符重载 运算符重载基础

函数重载(Function Overloading)可以让一个函数名有多种功能,在不同情况下进行不同的操作。运算符重载(Operator Overloading)也是一个道理,同一个运算符可以有不同的功能。

例子:用+号实现复数加法运算;成员函数重载运算符

#include <iostream> using namespace std; class complex{ public: complex(); complex(double real, double imag); public: //声明运算符重载 complex operator+(const complex &A) const; void display() const; private: double m_real; //实部 double m_imag; //虚部 }; complex::complex(): m_real(0.0), m_imag(0.0){ } complex::complex(double real, double imag): m_real(real), m_imag(imag){ } //实现运算符重载 complex complex::operator+(const complex &A) const{ return complex(this->m_real + A.m_real, this->m_imag + A.m_imag);//返回临时对象 } void complex::display() const{ cout<<m_real<<" + "<<m_imag<<"i"<<endl; } int main(){ complex c1(4.3, 5.8); complex c2(2.4, 3.7); complex c3; c3 = c1 + c2; c3.display();// 运行结果: 6.7 + 9.5i return 0; }

可以看出:运算符重载是通过函数实现的,它本质上是函数重载

运算符重载格式:

返回值类型 operator 运算符名称 (形参表列){
//TODO:
}

operator是关键字,专门用于定义重载运算符的函数。我们可以将`operator 运算符名称`这一部分看做函数名,对于上面的代码,函数名就是operator+

即是:运算符重载除了函数名不同,其他地方和函数没有什么区别;

初学C语言时,如何理解05版本的运算符重载?

当执行c3 = c1 + c2;语句时,编译器检测到+号左边(+号具有左结合性,所以先检测左边)是一个 complex 对象,就会调用成员函数operator+(),也就是转换为下面的形式:

c3 = c1.operator+(c2);

c1 是要调用函数的对象,c2 是函数的实参

全局内重载运算符:

运算符重载函数不仅可以作为类的成员函数,还可以作为全局函数。利用友元函数来实现(获取private属性,归属于全局函数的应用)

更改上述例子:

#include <iostream> using namespace std; class complex{ public: complex(); complex(double real, double imag); public: void display() const; //声明为友元函数 friend complex operator+(const complex &A, const complex &B); private: double m_real; double m_imag; }; complex operator+(const complex &A, const complex &B); complex::complex(): m_real(0.0), m_imag(0.0){ } complex::complex(double real, double imag): m_real(real), m_imag(imag){ } void complex::display() const{ cout<<m_real<<" + "<<m_imag<<"i"<<endl; } //在全局范围内重载+ complex operator+(const complex &A, const complex &B){ complex C; C.m_real = A.m_real + B.m_real; C.m_imag = A.m_imag + B.m_imag; return C; } int main(){ complex c1(4.3, 5.8); complex c2(2.4, 3.7); complex c3; c3 = c1 + c2; c3.display(); return 0; }

通过运算符重载,扩大了C++已有运算符的功能,使之能用于对象,更人性了hhh;

tip: 非静态成员函数后面加const(加到非成员函数或静态成员后面会产生编译错误,静态和非静态的区别就是,查看下面链接),表示成员函数隐含传入的this指针为const指针,决定了在该成员函数中,任意修改它所在的类的成员的操作都是不允许的(因为隐含了对this指针的const引用);唯一的例外是对于mutable修饰的成员。加了const的成员函数可以被非const对象和const对象调用,但不加const的成员函数只能被非const对象调用。静态函数和非静态函数的区别、什么是mutable

运算符重载的规则
  • 可以重载的运算符:+ - * / % ^ & | ~ ! = < > += -= = /= %= ^= &= |= << >> <<= >>= == != <= >= && || ++ -- , -> -> () [] new new[] delete delete[] ,自增自减运算符的前置和后置形式都可以重载

长度运算符sizeof、条件运算符: ?、成员选择符.和域解析运算符::不能被重载。

  • 重载不能改变运算符的优先级和结合性,如+-*/等运算符的优先级不会被改变;
  • 运算符重载函数不能有默认的参数,否则就改变了运算符操作数的个数(比如+号默认参数为1,结果肯定不对),这显然是错误的(有的博客说重载函数要有遵循固定数量的参数,和公认的相同)
  • 运算符重载函数既可以作为类的成员函数,也可以作为全局函数

将运算符重载函数作为类的成员函数时,二元运算符的参数只有一个,一元运算符不需要参数。之所以少一个参数,是因为这个参数是隐含的,是这个类对象本身;如上面的this,通过 this 指针隐式的访问 c1 的成员变量。

将运算符重载函数作为全局函数时,二元操作符就需要两个参数,一元操作符需要一个参数,而且其中必须至少有一个参数是对象,好让编译器区分这是程序员自定义的运算符,防止程序员修改用于内置类型的运算符的性质,比如:

int operator + (int a,int b){//显然错误,会造成歧义,改变内置类型的运算符的性质(别人设过的东西你别用) return (a-b); }

而如果上述的a或者b是一个对象,那么就是成立的;

同时,将运算符重载函数作为全局函数时,一般都需要在类中将该函数声明为友元函数。原因很简单,该函数大部分情况下都需要使用类的 private 成员。

  • 箭头运算符->、下标运算符[ ]、函数调用运算符( )、赋值运算符=只能以成员函数的形式重载。
重载数学运算符例子

实际开发中重载数学运算符号非常常见,比如c++只是定义了复数的==,我们来实现复数的+,-,*,例子如下:

#include <iostream> #include <cmath> using namespace std; //复数类 class Complex{ public: //构造函数 Complex(double real = 0.0, double imag = 0.0): m_real(real), m_imag(imag){ } public: //运算符重载 //以全局函数的形式重载!!!!!!!!!!! friend Complex operator+(const Complex &c1, const Complex &c2); friend Complex operator-(const Complex &c1, const Complex &c2); friend Complex operator*(const Complex &c1, const Complex &c2); friend Complex operator/(const Complex &c1, const Complex &c2); friend bool operator==(const Complex &c1, const Complex &c2); friend bool operator!=(const Complex &c1, const Complex &c2); //以成员函数的形式重载!!!!!!!!!!!! Complex & operator+=(const Complex &c); Complex & operator-=(const Complex &c); Complex & operator*=(const Complex &c); Complex & operator/=(const Complex &c); public: //成员函数 double real() const{ return m_real; } double imag() const{ return m_imag; } private: double m_real; //实部 double m_imag; //虚部 }; //重载+运算符 Complex operator+(const Complex &c1, const Complex &c2){ return Complex c; c.m_real = c1.m_real + c2.m_real; c.m_imag = c1.m_imag + c2.m_imag; return c; } //重载-运算符 Complex operator-(const Complex &c1, const Complex &c2){ Complex c; c.m_real = c1.m_real - c2.m_real; c.m_imag = c1.m_imag - c2.m_imag; return c; } //重载*运算符 (a+bi) * (c+di) = (ac-bd) + (bc+ad)i Complex operator*(const Complex &c1, const Complex &c2){ Complex c; c.m_real = c1.m_real * c2.m_real - c1.m_imag * c2.m_imag; c.m_imag = c1.m_imag * c2.m_real + c1.m_real * c2.m_imag; return c; } //重载/运算符 (a+bi) / (c+di) = [(ac+bd) / (c²+d²)] + [(bc-ad) / (c²+d²)]i Complex operator/(const Complex &c1, const Complex &c2){ Complex c; c.m_real = (c1.m_real*c2.m_real + c1.m_imag*c2.m_imag) / (pow(c2.m_real, 2) + pow(c2.m_imag, 2)); c.m_imag = (c1.m_imag*c2.m_real - c1.m_real*c2.m_imag) / (pow(c2.m_real, 2) + pow(c2.m_imag, 2)); return c; } //重载==运算符 bool operator==(const Complex &c1, const Complex &c2){ if( c1.m_real == c2.m_real && c1.m_imag == c2.m_imag ){ return true; }else{ return false; } } //重载!=运算符 bool operator!=(const Complex &c1, const Complex &c2){ if( c1.m_real != c2.m_real || c1.m_imag != c2.m_imag ){ return true; }else{ return false; } } //重载+=运算符,开始有&符号 Complex & Complex::operator+=(const Complex &c){ this->m_real += c.m_real; this->m_imag += c.m_imag; return *this;//this就是一个指针,*解引用,返回的是this指向的对象 } //重载-=运算符 Complex & Complex::operator-=(const Complex &c){ this->m_real -= c.m_real; this->m_imag -= c.m_imag; return *this; } //重载*=运算符 Complex & Complex::operator*=(const Complex &c){ this->m_real = this->m_real * c.m_real - this->m_imag * c.m_imag; this->m_imag = this->m_imag * c.m_real + this->m_real * c.m_imag; return *this; } //重载/=运算符 Complex & Complex::operator/=(const Complex &c){ this->m_real = (this->m_real*c.m_real + this->m_imag*c.m_imag) / (pow(c.m_real, 2) + pow(c.m_imag, 2)); this->m_imag = (this->m_imag*c.m_real - this->m_real*c.m_imag) / (pow(c.m_real, 2) + pow(c.m_imag, 2)); return *this; } int main(){ Complex c1(25, 35); Complex c2(10, 20); Complex c3(1, 2); Complex c4(4, 9); Complex c5(34, 6); Complex c6(80, 90); Complex c7 = c1 + c2; Complex c8 = c1 - c2; Complex c9 = c1 * c2; Complex c10 = c1 / c2; cout<<"c7 = "<<c7.real()<<" + "<<c7.imag()<<"i"<<endl; cout<<"c8 = "<<c8.real()<<" + "<<c8.imag()<<"i"<<endl; cout<<"c9 = "<<c9.real()<<" + "<<c9.imag()<<"i"<<endl; cout<<"c10 = "<<c10.real()<<" + "<<c10.imag()<<"i"<<endl; c3 += c1; c4 -= c2; c5 *= c2; c6 /= c2; cout<<"c3 = "<<c3.real()<<" + "<<c3.imag()<<"i"<<endl; cout<<"c4 = "<<c4.real()<<" + "<<c4.imag()<<"i"<<endl; cout<<"c5 = "<<c5.real()<<" + "<<c5.imag()<<"i"<<endl; cout<<"c6 = "<<c6.real()<<" + "<<c6.imag()<<"i"<<endl; if(c1 == c2){ cout<<"c1 == c2"<<endl; } if(c1 != c2){ cout<<"c1 != c2"<<endl; } return 0; }

运行结果:

选择是成员函数还是全局函数运算符重载

看例子:

Complex(double real): m_real(real), m_imag(0.0){ } //转换构造函数 //重载+号运算符,设置成全局函数运算符重载 Complex operator+(const Complex &c1, const Complex &c2) ..... Complex c2 = c1 + 15.6;//正确 Complex c3 = 28.23 + c1;//正确

为什么要设置成全局运算符呢?

因为如果设置成成员函数,Complex c3 = 28.23 + c1;将会是错误的;

原理:因为是全局函数,保证了 + 运算符的操作数能够被对称的处理,存在转换构造函数编译器在检测到 Complex 和 double(小数默认为 double 类型)相加时,会先尝试将 double 转换为 Complex,或者反过来将 Complex 转换为 double(只有类型相同的数据才能进行 + 运算),如果都转换失败,或者都转换成功(产生了二义性),才报错。本例中,编译器会先通过构造函数Complex(double real);将 double 转换为 Complex,再调用重载过的 + 进行计算,整个过程类似于下面的形式:

设置成成员函数:根据“+ 运算符具有左结合性”这条原则,Complex c3 = 28.23 + c1会被转换为Complex c3 = (28.23).operator+(c1),很显然这是错误的,因为 double 类型并没有以成员函数的形式重载 +。所以成员函数不能对此处理操作数;

为什么成员函数中不能用转换构造函数处理数据28.23为Complex(28.23),而全局函数可以?

C++ 只会对成员函数的参数进行类型转换,而不会对调用成员函数的对象进行类型转换,因为设置为成员函数,28.23不是函数的参数,是拥有该函数的类对象,调用的将是28.23这个double对象的重载+,明显是没有的该函数,会报错;而全局函数,那么调用的将是operator+(28.23, c1)这个函数,那么28.23,c1都是函数的参数,是可以调用转换构造函数的。

注意ψ(`∇´)ψ

本文共计3159个文字,预计阅读时间需要13分钟。

初学C语言时,如何理解05版本的运算符重载?

运算符重载允许一个函数名拥有多种功能,在特定情况下执行不同操作。运算符重载(Operator Overloading)也是一个理解,同一个运算符可以有不同的行为。

运算符重载 运算符重载基础

函数重载(Function Overloading)可以让一个函数名有多种功能,在不同情况下进行不同的操作。运算符重载(Operator Overloading)也是一个道理,同一个运算符可以有不同的功能。

例子:用+号实现复数加法运算;成员函数重载运算符

#include <iostream> using namespace std; class complex{ public: complex(); complex(double real, double imag); public: //声明运算符重载 complex operator+(const complex &A) const; void display() const; private: double m_real; //实部 double m_imag; //虚部 }; complex::complex(): m_real(0.0), m_imag(0.0){ } complex::complex(double real, double imag): m_real(real), m_imag(imag){ } //实现运算符重载 complex complex::operator+(const complex &A) const{ return complex(this->m_real + A.m_real, this->m_imag + A.m_imag);//返回临时对象 } void complex::display() const{ cout<<m_real<<" + "<<m_imag<<"i"<<endl; } int main(){ complex c1(4.3, 5.8); complex c2(2.4, 3.7); complex c3; c3 = c1 + c2; c3.display();// 运行结果: 6.7 + 9.5i return 0; }

可以看出:运算符重载是通过函数实现的,它本质上是函数重载

运算符重载格式:

返回值类型 operator 运算符名称 (形参表列){
//TODO:
}

operator是关键字,专门用于定义重载运算符的函数。我们可以将`operator 运算符名称`这一部分看做函数名,对于上面的代码,函数名就是operator+

即是:运算符重载除了函数名不同,其他地方和函数没有什么区别;

初学C语言时,如何理解05版本的运算符重载?

当执行c3 = c1 + c2;语句时,编译器检测到+号左边(+号具有左结合性,所以先检测左边)是一个 complex 对象,就会调用成员函数operator+(),也就是转换为下面的形式:

c3 = c1.operator+(c2);

c1 是要调用函数的对象,c2 是函数的实参

全局内重载运算符:

运算符重载函数不仅可以作为类的成员函数,还可以作为全局函数。利用友元函数来实现(获取private属性,归属于全局函数的应用)

更改上述例子:

#include <iostream> using namespace std; class complex{ public: complex(); complex(double real, double imag); public: void display() const; //声明为友元函数 friend complex operator+(const complex &A, const complex &B); private: double m_real; double m_imag; }; complex operator+(const complex &A, const complex &B); complex::complex(): m_real(0.0), m_imag(0.0){ } complex::complex(double real, double imag): m_real(real), m_imag(imag){ } void complex::display() const{ cout<<m_real<<" + "<<m_imag<<"i"<<endl; } //在全局范围内重载+ complex operator+(const complex &A, const complex &B){ complex C; C.m_real = A.m_real + B.m_real; C.m_imag = A.m_imag + B.m_imag; return C; } int main(){ complex c1(4.3, 5.8); complex c2(2.4, 3.7); complex c3; c3 = c1 + c2; c3.display(); return 0; }

通过运算符重载,扩大了C++已有运算符的功能,使之能用于对象,更人性了hhh;

tip: 非静态成员函数后面加const(加到非成员函数或静态成员后面会产生编译错误,静态和非静态的区别就是,查看下面链接),表示成员函数隐含传入的this指针为const指针,决定了在该成员函数中,任意修改它所在的类的成员的操作都是不允许的(因为隐含了对this指针的const引用);唯一的例外是对于mutable修饰的成员。加了const的成员函数可以被非const对象和const对象调用,但不加const的成员函数只能被非const对象调用。静态函数和非静态函数的区别、什么是mutable

运算符重载的规则
  • 可以重载的运算符:+ - * / % ^ & | ~ ! = < > += -= = /= %= ^= &= |= << >> <<= >>= == != <= >= && || ++ -- , -> -> () [] new new[] delete delete[] ,自增自减运算符的前置和后置形式都可以重载

长度运算符sizeof、条件运算符: ?、成员选择符.和域解析运算符::不能被重载。

  • 重载不能改变运算符的优先级和结合性,如+-*/等运算符的优先级不会被改变;
  • 运算符重载函数不能有默认的参数,否则就改变了运算符操作数的个数(比如+号默认参数为1,结果肯定不对),这显然是错误的(有的博客说重载函数要有遵循固定数量的参数,和公认的相同)
  • 运算符重载函数既可以作为类的成员函数,也可以作为全局函数

将运算符重载函数作为类的成员函数时,二元运算符的参数只有一个,一元运算符不需要参数。之所以少一个参数,是因为这个参数是隐含的,是这个类对象本身;如上面的this,通过 this 指针隐式的访问 c1 的成员变量。

将运算符重载函数作为全局函数时,二元操作符就需要两个参数,一元操作符需要一个参数,而且其中必须至少有一个参数是对象,好让编译器区分这是程序员自定义的运算符,防止程序员修改用于内置类型的运算符的性质,比如:

int operator + (int a,int b){//显然错误,会造成歧义,改变内置类型的运算符的性质(别人设过的东西你别用) return (a-b); }

而如果上述的a或者b是一个对象,那么就是成立的;

同时,将运算符重载函数作为全局函数时,一般都需要在类中将该函数声明为友元函数。原因很简单,该函数大部分情况下都需要使用类的 private 成员。

  • 箭头运算符->、下标运算符[ ]、函数调用运算符( )、赋值运算符=只能以成员函数的形式重载。
重载数学运算符例子

实际开发中重载数学运算符号非常常见,比如c++只是定义了复数的==,我们来实现复数的+,-,*,例子如下:

#include <iostream> #include <cmath> using namespace std; //复数类 class Complex{ public: //构造函数 Complex(double real = 0.0, double imag = 0.0): m_real(real), m_imag(imag){ } public: //运算符重载 //以全局函数的形式重载!!!!!!!!!!! friend Complex operator+(const Complex &c1, const Complex &c2); friend Complex operator-(const Complex &c1, const Complex &c2); friend Complex operator*(const Complex &c1, const Complex &c2); friend Complex operator/(const Complex &c1, const Complex &c2); friend bool operator==(const Complex &c1, const Complex &c2); friend bool operator!=(const Complex &c1, const Complex &c2); //以成员函数的形式重载!!!!!!!!!!!! Complex & operator+=(const Complex &c); Complex & operator-=(const Complex &c); Complex & operator*=(const Complex &c); Complex & operator/=(const Complex &c); public: //成员函数 double real() const{ return m_real; } double imag() const{ return m_imag; } private: double m_real; //实部 double m_imag; //虚部 }; //重载+运算符 Complex operator+(const Complex &c1, const Complex &c2){ return Complex c; c.m_real = c1.m_real + c2.m_real; c.m_imag = c1.m_imag + c2.m_imag; return c; } //重载-运算符 Complex operator-(const Complex &c1, const Complex &c2){ Complex c; c.m_real = c1.m_real - c2.m_real; c.m_imag = c1.m_imag - c2.m_imag; return c; } //重载*运算符 (a+bi) * (c+di) = (ac-bd) + (bc+ad)i Complex operator*(const Complex &c1, const Complex &c2){ Complex c; c.m_real = c1.m_real * c2.m_real - c1.m_imag * c2.m_imag; c.m_imag = c1.m_imag * c2.m_real + c1.m_real * c2.m_imag; return c; } //重载/运算符 (a+bi) / (c+di) = [(ac+bd) / (c²+d²)] + [(bc-ad) / (c²+d²)]i Complex operator/(const Complex &c1, const Complex &c2){ Complex c; c.m_real = (c1.m_real*c2.m_real + c1.m_imag*c2.m_imag) / (pow(c2.m_real, 2) + pow(c2.m_imag, 2)); c.m_imag = (c1.m_imag*c2.m_real - c1.m_real*c2.m_imag) / (pow(c2.m_real, 2) + pow(c2.m_imag, 2)); return c; } //重载==运算符 bool operator==(const Complex &c1, const Complex &c2){ if( c1.m_real == c2.m_real && c1.m_imag == c2.m_imag ){ return true; }else{ return false; } } //重载!=运算符 bool operator!=(const Complex &c1, const Complex &c2){ if( c1.m_real != c2.m_real || c1.m_imag != c2.m_imag ){ return true; }else{ return false; } } //重载+=运算符,开始有&符号 Complex & Complex::operator+=(const Complex &c){ this->m_real += c.m_real; this->m_imag += c.m_imag; return *this;//this就是一个指针,*解引用,返回的是this指向的对象 } //重载-=运算符 Complex & Complex::operator-=(const Complex &c){ this->m_real -= c.m_real; this->m_imag -= c.m_imag; return *this; } //重载*=运算符 Complex & Complex::operator*=(const Complex &c){ this->m_real = this->m_real * c.m_real - this->m_imag * c.m_imag; this->m_imag = this->m_imag * c.m_real + this->m_real * c.m_imag; return *this; } //重载/=运算符 Complex & Complex::operator/=(const Complex &c){ this->m_real = (this->m_real*c.m_real + this->m_imag*c.m_imag) / (pow(c.m_real, 2) + pow(c.m_imag, 2)); this->m_imag = (this->m_imag*c.m_real - this->m_real*c.m_imag) / (pow(c.m_real, 2) + pow(c.m_imag, 2)); return *this; } int main(){ Complex c1(25, 35); Complex c2(10, 20); Complex c3(1, 2); Complex c4(4, 9); Complex c5(34, 6); Complex c6(80, 90); Complex c7 = c1 + c2; Complex c8 = c1 - c2; Complex c9 = c1 * c2; Complex c10 = c1 / c2; cout<<"c7 = "<<c7.real()<<" + "<<c7.imag()<<"i"<<endl; cout<<"c8 = "<<c8.real()<<" + "<<c8.imag()<<"i"<<endl; cout<<"c9 = "<<c9.real()<<" + "<<c9.imag()<<"i"<<endl; cout<<"c10 = "<<c10.real()<<" + "<<c10.imag()<<"i"<<endl; c3 += c1; c4 -= c2; c5 *= c2; c6 /= c2; cout<<"c3 = "<<c3.real()<<" + "<<c3.imag()<<"i"<<endl; cout<<"c4 = "<<c4.real()<<" + "<<c4.imag()<<"i"<<endl; cout<<"c5 = "<<c5.real()<<" + "<<c5.imag()<<"i"<<endl; cout<<"c6 = "<<c6.real()<<" + "<<c6.imag()<<"i"<<endl; if(c1 == c2){ cout<<"c1 == c2"<<endl; } if(c1 != c2){ cout<<"c1 != c2"<<endl; } return 0; }

运行结果:

选择是成员函数还是全局函数运算符重载

看例子:

Complex(double real): m_real(real), m_imag(0.0){ } //转换构造函数 //重载+号运算符,设置成全局函数运算符重载 Complex operator+(const Complex &c1, const Complex &c2) ..... Complex c2 = c1 + 15.6;//正确 Complex c3 = 28.23 + c1;//正确

为什么要设置成全局运算符呢?

因为如果设置成成员函数,Complex c3 = 28.23 + c1;将会是错误的;

原理:因为是全局函数,保证了 + 运算符的操作数能够被对称的处理,存在转换构造函数编译器在检测到 Complex 和 double(小数默认为 double 类型)相加时,会先尝试将 double 转换为 Complex,或者反过来将 Complex 转换为 double(只有类型相同的数据才能进行 + 运算),如果都转换失败,或者都转换成功(产生了二义性),才报错。本例中,编译器会先通过构造函数Complex(double real);将 double 转换为 Complex,再调用重载过的 + 进行计算,整个过程类似于下面的形式:

设置成成员函数:根据“+ 运算符具有左结合性”这条原则,Complex c3 = 28.23 + c1会被转换为Complex c3 = (28.23).operator+(c1),很显然这是错误的,因为 double 类型并没有以成员函数的形式重载 +。所以成员函数不能对此处理操作数;

为什么成员函数中不能用转换构造函数处理数据28.23为Complex(28.23),而全局函数可以?

C++ 只会对成员函数的参数进行类型转换,而不会对调用成员函数的对象进行类型转换,因为设置为成员函数,28.23不是函数的参数,是拥有该函数的类对象,调用的将是28.23这个double对象的重载+,明显是没有的该函数,会报错;而全局函数,那么调用的将是operator+(28.23, c1)这个函数,那么28.23,c1都是函数的参数,是可以调用转换构造函数的。

注意ψ(`∇´)ψ