###Implicit conversions隐式转换
* 可以在基本类型之间自由转换;
* 可以把任何类型的pointer转换为void pointer;
* 可以将子类pointer转换为基类pointer;
* 会产生warning

###static_cast静态转换
* 类似于implicit cast
* 可以在子类基类pointer之间自由转换
* 没有运行时检查

###dynamic_cast动态转换
* 一般用于polymorphism
* 会检查pointer是否指向valid object

###reinterpret_cast
* 可以在任意类型pointer之间进行转换
* 没有检查,非常危险

###const_cast
* 可以在const 和 non const pointer 之间转换

###C style cast
(type) val 或 type(val), 按照以下优先顺序转换:

* const_cast
* static_cast (though ignoring access restrictions
* static_cast (see above), then const_cast
* reinterpret_cast
* reinterpret_cast, then const_cast

Type conversions in C++类型转换的更多相关文章

  1. 条款24:若所有参数皆需要类型转换,请为此采用non-member函数(Declare non-member functions when type conversions should apply to all parameters)

    NOTE: 1.如果你需要为某个函数的所有参数(包括this指针所指的那个隐喻参数)进行类型转换,那么这个函数必须是个non-member.

  2. A Tour of Go Type conversions

    The expression T(v) converts the value v to the type T. Some numeric conversions: var i int = 42 var ...

  3. [Compose] 20. Principled type conversions with Natural Transformations

    We learn what a natural transformation is and see the laws it must obey. We will see how a natural t ...

  4. C++: Type conversions

    1.static_cast     static_cast可以转换相关联的类,可以从子类转换成父类.也能从父类转向子类,但是如果转换的父类指针(或者父类引用)所指向的对象是完整的,那么是没有问题:但是 ...

  5. .NET Core全新路线图(译)

    标签: .NETCore 翻译 承接张善友大大的.NET Core全新路线图,翻译了原文,水平有限,尽量一观. 原文地址<.NET Core Roadmap>,原作者Scott Hunte ...

  6. EntityFramework Core技术线路(EF7已经更名为EF Core,并于2016年6月底发布)

    官方文档英文地址:https://github.com/aspnet/EntityFramework/wiki/Roadmap 历经延期和更名,新版本的实体框架终于要和大家见面了,虽然还有点害羞.请大 ...

  7. [转]EntityFramework Core技术线路(EF7已经更名为EF Core,并于2016年6月底发布)

    本文转自:http://www.cnblogs.com/VolcanoCloud/p/5572408.html 官方文档英文地址:https://github.com/aspnet/EntityFra ...

  8. C++ 词汇表

    C++词汇表 A abort()                       特殊函数 如果一个函数抛出异常,但在通往异常函数的调用链中找不到与之匹配的catch,则该程序通常以此函数调用终止 abs ...

  9. 4. Retrieving a mapper(检索映射器)

    Retrieving a mapper(检索映射器) 4.1. The Mappers factory(映射工厂) 可以通过 org.mapstruct.factory.Mappers 类检索映射器实 ...

随机推荐

  1. toString方法的用法

    public class JLDtoS {   public static void main(String[]args)   {    long a=123;    Long aa=new Long ...

  2. 神龟快跑,2016做的一款UWP游戏

    神龟快跑,2016做的一款UWP游戏, 实际是H5页面, 用LAYA转AS3得到的 安装地址 https://www.microsoft.com/zh-cn/store/p/神龟快跑/9nblggh4 ...

  3. popupMenu-----弹出菜单

    import android.os.Bundle; import android.app.Activity; import android.graphics.Color; import android ...

  4. 源码安装php时出现Sorry, I cannot run apxs. Possible reasons follow:

    1.可能的原因是你没有安装perl > yum install perl > yum install httpd-devel 2.在你apache安装目录下的bin下找到apxs,并用vi ...

  5. golang协程进行同步方法

    1.使用chanel func main() { done := make(chan bool) ticker := time.NewTicker(time.Millisecond * 1000) g ...

  6. win, cmd下安装mysql(win真tm难用)

    常用命令: 修改root用户密码 update mysql.user set authentication_string=password('1234qwer') where user='root' ...

  7. Java数据结构和算法(一)散列表

    Java数据结构和算法(一)散列表 数据结构与算法目录(https://www.cnblogs.com/binarylei/p/10115867.html) 散列表(Hash table) 也叫哈希表 ...

  8. iis 应用程序预热

    <applicationPools> <add name="appname" managedRuntimeVersion="v4.0" sta ...

  9. maven web 项目 打入 jar 包 , 和编译入 java 文件到 web-inf 下

    <outputDirectory>src\main\webapp\WEB-INF\classes</outputDirectory> 可以把 类文件编译到 web-inf 下 ...

  10. 经典递归问题:0,1背包问题 kmp 用遗传算法来解背包问题,hash表,位图法搜索,最长公共子序列

    0,1背包问题:我写笔记风格就是想到哪里写哪里,有很多是旧的也没删除,代码内部可能有很多重复的东西,但是保证能运行出最后效果 '''学点高大上的遗传算法''' '''首先是Np问题的定义: npc:多 ...