• 数据类型转换(static_cast)

    //数据类型转换
    printf("%d\n", static_cast<int>(10.2));
  • 指针类型转换(reinterpret_cast)
     指针类型转换
    int *pint = new int();
    char *pch = reinterpret_cast<char *>(pint);
  • 涉及到const的指针类型转换(const_cast)
     const int num[] = { ,,,, };
    const int *p = num;
    int *pint = const_cast<int *>(p);
  • 子类转化为父类(dynamic_cast)
     class man
    {
    public:
    int name;
    //加上virtual关键字,可以使得父类用子类初始化后可以调用子类的函数
    virtual void run()
    {
    cout << "man is running" << endl;
    }
    }; class son :public man
    {
    public:
    void run()
    {
    cout << "son is running" << endl;
    }
    }; void main()
    {
    /*man man1;
    son son1;
    man *p = &man1;
    p->run();
    p = &son1;
    p->run();*/
    man *pman = new man;
    son *pson = new son;
    //子类指针转换为父类指针,但是还是调用子类的函数
    man *pfu = dynamic_cast<man *>(pson);
    pfu->run();
    system("pause");
    }

43.c++指针类型转换的更多相关文章

  1. C语言中将0到1000的浮点数用强制指针类型转换的方式生成一幅图像

    搞过计算机图像的人都知道,图像中的每一个像素通常为一个整型数,它可以分成4个无符号的char类型,以表示其RGBA四个分量.一幅图像可以看做是一个二维整型数组.这里我会生成一个float数组,其数组大 ...

  2. c++ 指针类型转换

    1.数据类型转换(static_cast) //数据类型转换printf("%d\n", static_cast<int>(10.2)); 2.指针类型转换(reint ...

  3. C指针类型转换问题

    先看下面的代码: #include<stdio.h> int main () { int a; char *x; x = (char *) &a; a = 512; x[0] = ...

  4. C++_知识点_指针类型转换

    #include <iostream> using namespace std; int main(){ ] = {, , , , , , , , , }; int* p = (int*) ...

  5. C++智能指针类型转换

    #include <iostream> #include <memory> struct Base { int a; virtual void f() const { std: ...

  6. [翻译]类型双关不好玩:C中使用指针重新解释是坏的

    原文地址 Type punning isn't funny: Using pointers to recast in C is bad. C语言中一个重新解释(reinterpret)数据类型的技巧有 ...

  7. 对象布局已知时 C++ 对象指针的转换时地址调整

    在我调试和研究 netscape 系浏览器插件开发时,注意到了这个问题.即,在对象布局已知(即对象之间具有继承关系)时,不同类型对象的指针进行转换(不管是隐式的从下向上转换,还是强制的从上到下转换)时 ...

  8. 【面经】【转】C++类型转换

    C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是:type b = (type) a. C++风格的类型转换提供了4种类型转换操作符来应对不同场景的应用. const_cas ...

  9. C++ 四种强制类型转换

    来自csdn:http://blog.csdn.net/hgl868/article/details/46619399 C风格的强制类转换(Type Cast)很简单,不管什么类型的转换统统是: TY ...

随机推荐

  1. [Poi] Build a Vue App with Poi

    Poi uses the Vue babel presets by default, so there is no additional install required to get up-and- ...

  2. cocos2d-x 2.2.0 怎样在lua中注冊回调函数给C++

    cocos2d-x内部使用tolua进行lua绑定.可是引擎并没有提供一个通用的接口让我们能够把一个lua函数注冊给C++层面的回调事件. 翻看引擎的lua绑定代码,我们能够仿照引擎中的方法来做. 值 ...

  3. vue19 组建 Vue.extend component、组件模版、动态组件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 在spring-mybatis.xml 中配置pagehelper

    maven导包:<dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</ ...

  5. Sqoop-1.4.6工具import和export使用详解(官网)

    不多说,直接上干货! 1.Sqoop Import (进入官网) 因为,sqoop的使用方式是: sqoop COMMAND  ARGS. 以下是  sqoop COMMAND  ARGS 以下是   ...

  6. OpenCV中数据转换

    在OpenCV中Mat.CvMat和IplImage类型都可以代表和显示图像.IplImage由CvMat派生,而CvMat由CvArr派生即CvArr -> CvMat -> IplIm ...

  7. 目前常见的三种SQL分页方式:

    --top not in方式 select top 条数 * from tablename where Id not in (select top 条数*页数 Id from tablename) - ...

  8. 网络爬虫与web之间的访问授权协议——Robots

    网站的管理者们通常会有这样一种心态:一方面期待百度.Google这样的搜索引擎来抓取网站的内容,另一方面又很厌恶其他来路不明的网络爬虫抓取自己的信息.正是因为这样,才有“好爬虫”.“坏爬虫”这样的说法 ...

  9. Python excel 功能扩展库 ——> openpyxl 的基本使用

    说明:本文档内容参考自 https://www.cnblogs.com/zeke-python-road/p/8986318.html (作者:关关雎鸠`)的文档 from openpyxl impo ...

  10. Django_模板HTML