/*类型转换函数一般用于将类型转换为基本数据类型,但也可以转换为构造类型,如下*/
#include <stdlib.h>
#include<iostream>
#include <stdio.h>
#include<cmath>
using namespace std;
class Point
{
private:
 double x;
public:
 Point(double a= 0):x(a){};
 void Show(){cout<<"x:"<<x<<endl;}
};
class A
{
protected:
 double a;
public:
 A(double x =0):a(x){}
 double Geta(){return a;}
};
class B: public A
{
public:
 B(double x= 0):A(x){}
 operator Point(){
  return Point(Geta());
 }
};
int main()
{
 B obj1(18);
 Point obj2=obj1;//可以隐式调用
 //Point obj2=obj1.operator Point();//也可以显示调用
 obj2.Show();
 return 0;
}

 

相关文章:

  • 2022-12-23
  • 2021-06-01
  • 2021-07-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-10-31
相关资源
相似解决方案