Type Conversion(类型转换)

Two kinds of type conversion

  • explict type conversion(显式类型转换)

  • impict type conversion(隐式类型转换)

Two way to  convert type

  • 赋值

  • 构造函数

  • 转换函数

转换函数

不支持friend

类与类转换

 #include <iostream>

 class mianji
{
public:
friend class fushu;
mianji()
{
this->cx = ;
this->cy = ;
}
void setxy(int a,int b)
{
this->cx = a;
this->cy = b;
}
protected:
private:
int cx;
int cy;
}; class fushu
{
public:
friend class mianji;//ÓÑÔª¿ÉÒÔ·ÃÎÊ˽ÓбäÁ¿
fushu(mianji mianji1)
{
this->x = mianji1.cx;
this->y = mianji1.cy;
}
void print()
{
std::cout << x << "+" << y << "i" << std::endl;
}
operator mianji()
{
mianji temp;
temp.cx = x;
temp.cy = y;
return temp;
} protected:
private:
int x;
int y;
}; void main()
{
mianji mianji1;
fushu fushu1 =(fushu) mianji1;//通过构造函数转换
fushu fushu1(mianji1);//通过构造函数转换 mianji mianji2;
mianji2.setxy(, ); fushu1 = mianji2;//通过构造函数转换
mianji2 = fushu1;//通过转换函数来转换
fushu1.print();
std::cin.get();
}

[C++] Type Conversion(类型转换)的更多相关文章

  1. delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决

    delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决,需要打这个 ...

  2. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(一)

    题外话:本篇是对之前那篇的重排版.并拆分成两篇,免得没了看的兴趣. 前言 在Spring Framework官方文档中,这三者是放到一起讲的,但没有解释为什么放到一起.大概是默认了读者都是有相关经验的 ...

  3. go学习笔记-类型转换(Type Conversion)

    类型转换(Type Conversion) 类型转换用于将一种数据类型的变量转换为另外一种类型的变,基本格式 type_name(expression) type_name 为类型,expressio ...

  4. Spring Type Conversion(Spring类型转换)

    Spring Type Conversion(Spring类型转换) 1:概述: Spring3引入了core.convert包,提供了通用类型转换系统,定义了实现类型转换和运行时执行类型的SPI. ...

  5. Type Conversion

    文章著作权归作者所有.转载请联系作者,并在文中注明出处,给出原文链接. 本文原更新于作者的github博客,这里给出链接. 什么是转换 转换是接受一个类型的值并使用它作为另一个类型的等价值的过程.转换 ...

  6. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(二)

    接前一篇 Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 本篇主要内容:Spring Type Conver ...

  7. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion

    本篇太乱,请移步: Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 写了删删了写,反复几次,对自己的描述很不 ...

  8. JavaScript Type Conversion

    Data Types 5 Data Types string, number, boolean, object, function 3 Object Types object, array, date ...

  9. error: expected constructor, destructor, or type conversion before '.' token

    今天写代码是遇到这样一个问题error: expected constructor, destructor, or type conversion before '.' token:立马网上查,原来是 ...

随机推荐

  1. JAVASE02-Unit011: TCP通信(小程序)

    TCP通信(小程序) server端: package chat; import java.io.BufferedReader; import java.io.IOException; import ...

  2. flv 解封装

    #include <stdio.h> #include <stdlib.h> #include <string.h> #define DEBUG_INFO type ...

  3. 汇编_指令_CS与DS的区别

    cs是值cpu执行的当前指令的段地址,ds是数据开始的段地址. CS是告诉CPU,去哪个位置找内容当成指令去执行:DS是告诉CPU,去哪个位置找内容当成数据被使用. datastring =ds co ...

  4. git 怎么上传文件到github上

    1.安装git     sudo  apt-get install git 2.配置全局变量     git config --global user.name langhunm     git co ...

  5. js与jQuery的区分

    Js与Jquery的区分

  6. DBA_2PC_PENDING (转)

    DBA_2PC_PENDINGOracle会自动处理分布事务,保证分布事务的一致性,所有站点全部提交或全部回滚.一般情况下,处理过程在很短的时间内完成,根本无法察觉到.但是,如果在commit或rol ...

  7. 3_python之路之商城购物车

    python之路之商城购物车 1.程序说明:Readme.txt 1.程序文件:storeapp_new.py userinfo.py 2.程序文件说明:storeapp_new.py-主程序 use ...

  8. Log4j记录日志使用方法

    1.导入相关JAR包 log4j-1.2.15.jar slf4j-api-1.6.1.jar slf4j-log4j12-1.6.1.jar log4jdbc4-1.2.jar 2.配置log4j. ...

  9. eclipse中导入web项目时,出现转不了项目类型的问题解决方案

    解决步骤: 1.进入项目目录,可看到.project文件,文本编辑器打开. 2.找到<natures>...</natures>代码段,加入如下标签内容并保存: <nat ...

  10. 05_java之方法

    01方法的概述 * A: 为什么要有方法 * 提高代码的复用性 * B: 什么是方法 * 完成特定功能的代码块. 02方法的定义格式 * A: 方法的格式 * 修饰符 返回值类型 方法名(参数类型 参 ...