[C++] Type Conversion(类型转换)
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(类型转换)的更多相关文章
- delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决
delphi 10.1 berlin datasnap提交clientdataset.delta报:invalid variant type conversion(类型转换错误)问题的解决,需要打这个 ...
- Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(一)
题外话:本篇是对之前那篇的重排版.并拆分成两篇,免得没了看的兴趣. 前言 在Spring Framework官方文档中,这三者是放到一起讲的,但没有解释为什么放到一起.大概是默认了读者都是有相关经验的 ...
- go学习笔记-类型转换(Type Conversion)
类型转换(Type Conversion) 类型转换用于将一种数据类型的变量转换为另外一种类型的变,基本格式 type_name(expression) type_name 为类型,expressio ...
- Spring Type Conversion(Spring类型转换)
Spring Type Conversion(Spring类型转换) 1:概述: Spring3引入了core.convert包,提供了通用类型转换系统,定义了实现类型转换和运行时执行类型的SPI. ...
- Type Conversion
文章著作权归作者所有.转载请联系作者,并在文中注明出处,给出原文链接. 本文原更新于作者的github博客,这里给出链接. 什么是转换 转换是接受一个类型的值并使用它作为另一个类型的等价值的过程.转换 ...
- Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(二)
接前一篇 Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 本篇主要内容:Spring Type Conver ...
- Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion
本篇太乱,请移步: Spring Framework 官方文档学习(四)之Validation.Data Binding.Type Conversion(一) 写了删删了写,反复几次,对自己的描述很不 ...
- JavaScript Type Conversion
Data Types 5 Data Types string, number, boolean, object, function 3 Object Types object, array, date ...
- error: expected constructor, destructor, or type conversion before '.' token
今天写代码是遇到这样一个问题error: expected constructor, destructor, or type conversion before '.' token:立马网上查,原来是 ...
随机推荐
- Java里的常用运算符及其优先级顺序
知道了八种基本数据类型后,在使用中弄清运算符的优先级是很有必要的.具体如下图: 这里需要注意的是,强制类型转换的优先级是位于乘除前面而处于单目运算符后面的,这是比较容易出错的地方.比如用Math.R ...
- 在不适用fixed的前提下,当内容较少时footer固定在页面底部
使用css,参考国外的一个解决方法: http://ryanfait.com/resources/footer-stick-to-bottom-of-page/ How to use the CSS ...
- struts2学习(5)拦截器简介以及例子执行过程
一.拦截器简介: 二.Struts2预定义拦截器&拦截器栈 在执行action之前和之后,拦截器进行了操作: 比如struts-default.xml中就有很多预定义的拦截器: 拦截器栈: ...
- 阻塞队列之五:LinkedBlockingQueue
一.LinkedBlockingQueue简介 LinkedBlockingQueue是一个使用链表完成队列操作的阻塞队列.链表是单向链表,而不是双向链表.采用对于的next构成链表的方式来存储对象. ...
- jQuery给控件赋值....
1.jQuery给span取值:$("#id").html(); 2.jQuery给input取值:$("#id").val(); 3.jQuery给texta ...
- HTTP Get与Post请求
HTTP定义了与服务器交互的不同方法,最基本的方法有4种,分别是GET,POST,PUT,DELETE.URL全称是资源描述符,我们可以这样认为:一个URL地址,它用于描述一个网络上的资源,而HTTP ...
- laravel5中添加自定义函数
laravel里面我们很多朋友不知道把自定义函数放在哪儿.我们的应用里经常会有一些全局都可能会用的函数,我们应该怎么放置它会比较好呢?现在匀们为大家准备了laravel放置函数的规范. 1. 创建文件 ...
- supervisor 管理
Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启.它是通过fork/exec的方式把这些被管理的进程 ...
- Java死锁以及命令检测
Java每个对象都有一把锁,当前进程使用对象锁1,没有释放该锁,又想要去获取另一把对象锁2,而对象锁2被另外一个线程持有,没有释放,这就很容易出现死锁 1.死锁实例 public class Dead ...
- ceph journal更换位置
只在这里做简单的演示 ceotos7 环境 3个mon节点 3个osd节点 环境搭建我这里不再叙述 我们查看一下分区情况: [root@ceph_1 ~]# lsblkNAME MAJ: ...