当前位置: 首页 > news >正文

网站建设案例分析seo顾问服务福建

网站建设案例分析,seo顾问服务福建,如何制作自己的网址链接,宁波网站推广优化文章目录 C的类型转换C的4种强制类型转换RTTI C的类型转换 类型转换 内置类型之间的转换 // a、内置类型之间 // 1、隐式类型转换 整形之间/整形和浮点数之间 // 2、显示类型的转换 指针和整形、指针之间 int main() {int i 1;// 隐式类型转换double d i;printf("%d…

文章目录

  • C++的类型转换
    • C++的4种强制类型转换
    • RTTI

C++的类型转换

  • 类型转换

    • 内置类型之间的转换

      // a、内置类型之间
      // 1、隐式类型转换    整形之间/整形和浮点数之间
      // 2、显示类型的转换  指针和整形、指针之间
      int main()
      {int i = 1;// 隐式类型转换double d = i;printf("%d, %.2f\n", i, d);int* p = &i;// 显示的强制类型转换int address = (int)p;printf("%p, %d\n", p, address);return 0;
      }
      
    • 内置类型与自定义类型之间的类型转换

      • 内置类型转自定义类型:通过 自定义类型的 构造函数,使得内置类型可以转换为自定义类型

      • 自定义类型转内置类型:通过operator语法来实现 自定义类型转换为 内置类型
        operator + 允许类型转换的类型(),该语法比较特殊,不用写返回值,但是函数体有返回值,返回值类型是 允许类型转换的类型

      • 样例

        // b、内置类型和自定义类型之间
        // 1、自定义类型 = 内置类型  ->构造函数支持
        // 2、内置类型 = 自定义类型
        class A
        {
        public://explicit A(int a)A(int a):_a1(a),_a2(a){}A(int a1, int a2):_a1(a1), _a2(a2){}// ()被仿函数占用了,不能用// operator 类型实现,无返回类型//explicit operator int() //explicit关键字是禁止隐式类型转换,此处是禁止 A 隐式类型转换为 intoperator int(){return _a1 + _a2;}
        private:int _a1 = 1;int _a2 = 1;
        };
        int main()
        {string s1 = "1111111";//这就是 内置类型 通过 构造函数 隐式类型转化为 string 类型A aa1 = 1;//A aa1 = (A)1;A aa2 = { 2,2 };const A& aa3 = { 2,2 };int z = aa1.operator int();//int x = (int)aa1;int x = aa1;int y = aa2;cout << x << endl;cout << y << endl;std::shared_ptr<int> foo;std::shared_ptr<int> bar(new int(34));//if (foo.operator bool())if (foo)std::cout << "foo points to " << *foo << '\n';else std::cout << "foo is null\n";if (bar)std::cout << "bar points to " << *bar << '\n';elsestd::cout << "bar is null\n";return 0;
        }
        
    • 自定义类型与自定义类型之间的类型转换:通过对应的构造函数支持

      // c、自定义类型和自定义类型之间 -- 对应的构造函数支持
      class A
      {
      public:A(int a):_a1(a), _a2(a){}A(int a1, int a2):_a1(a1), _a2(a2){}int get() const{return _a1 + _a2;}
      private:int _a1 = 1;int _a2 = 1;
      };class B
      {
      public:B(int b):_b1(b){}B(const A& aa):_b1(aa.get()){}private:int _b1 = 1;
      };
      

C++的4种强制类型转换

标准C++为了加强类型转换的可视性,引入了四种命名的强制类型转换操作符:static_cast、reinterpret_cast、const_cast、dynamic_cast

  • static_cast

    static_cast用于非多态类型的转换(静态转换),编译器隐式执行的任何类型转换都可用 static_cast,但它不能用于两个不相关的类型进行转换

    语法: static_cast<要隐式转为的类型>(被转的变量);

    int main(){double d = 12.34;int a = static_cast<int>(d);cout<<a<<endl;return 0;}
    
  • reinterpret_cast

    reinterpret_cast操作符通常为操作数的位模式提供较低层次的重新解释,用于将一种类型转换 为另一种不同的类型。即reinterpret_cast对应强制类型转换,数据的意义已经发生改变

    语法:reinterpret_cast<要隐式转为的类型>(被转的变量);

    int main(){double d = 12.34;int a = static_cast<int>(d);cout << a << endl;// 这里使用static_cast会报错,应该使用reinterpret_cast//int *p = static_cast<int*>(a);int *p = reinterpret_cast<int*>(a);return 0;}
    
  • const_cast

    const_cast最常用的用途就是删除变量的const属性,方便赋值

    对应强制类型转换中有风险的去掉const属性的操作

    语法:const_cast<要隐式转为的类型>(被转的变量);
    volatile 修饰const变量,表明取变量的值时是去内存中去。 const 变量 正常情况下是被编译器用宏替代的/取值时从寄存器中取的。

    int main()
    {// 对应隐式类型转换 -- 数据的意义没有改变double d = 12.34;int a = static_cast<int>(d);// 对应强制类型转换中有风险的去掉const属性volatile const int b = 2;//此处如果没有volatile修饰,那么下文打印的b的结果还是2,但是实际上调试等操作可以看到b在内存中的值已经被修改了,那为什么打印出来是2呢?因为vs优化 const变量是直接被宏替代的,这个过程是编译过去中进行的,而改变b的值的操作是运行时进行的。int* p2 = const_cast<int*>(&b);*p2 = 3;cout << b << endl;cout << *p2 << endl;return 0;
    }
    
  • dynamic_cast

    dynamic_cast用于将一个父类对象的指针/引用转换为子类对象的指针或引用(动态转换) 。 即 dynamic_cast 用于 父类和子类之间的转换

    父类和子类之间转换分为两种
    **向上转型:子类对象指针/引用->父类指针/引用(不需要转换,赋值兼容规则) **

    向下转型:父类对象指针/引用->子类指针/引用(用dynamic_cast转型是安全的)

    dynamic_cast使用的范围:dynamic_cast只能用于父类含有虚函数的类

    优点:dynamic_cast会先检查是否能转换成功,能成功则转换,不能则返回0
    怎么算成功?怎么算不成功呢?
    *向上转型是赋值兼容规则,都是兼容的。 对于向下转型而言, 如果进行转换的指针/引用本身是指向父类的指针(注意:这里不是指 指针的类型,而是指 指针的指向的对象),那么它就会转换失败【失败的原因:对一个本来指向父类的指针进行强转为指向子类的指针,这就对父类添加了子类成员构造成了子类,存在风险】。如果进行转换的指针/引用本身是指向子类的指针

    class A
    {
    public:virtual void f() {}
    };
    class B : public A
    {};
    void fun(A* pa)
    {// dynamic_cast会先检查是否能转换成功,能成功则转换,不能则返回B* pb1 = static_cast<B*>(pa);//其实reinterpret_cast也能转换,但是不安全,因为它们不会对其进行检查B* pb2 = dynamic_cast<B*>(pa);cout << "pb1:" << pb1 << endl;cout << "pb2:" << pb2 << endl;
    }
    int main()
    {A a;B b;fun(&a);fun(&b);return 0;
    }
    

RTTI

  • 概念:RTTI是指 运行时类型识别
  • C++通过以下方式来支持RTTI
    1. typeid运算符:返回字面为数据的类型的字符串。(即int类型转换成"int")
    2. dynamic_cast运算符
    3. decltype

文章转载自:
http://germless.c7501.cn
http://ol.c7501.cn
http://divestment.c7501.cn
http://splosh.c7501.cn
http://sandwort.c7501.cn
http://tpi.c7501.cn
http://pensionless.c7501.cn
http://revolera.c7501.cn
http://quag.c7501.cn
http://isadora.c7501.cn
http://unlooked.c7501.cn
http://castor.c7501.cn
http://overrigid.c7501.cn
http://denobilize.c7501.cn
http://germinator.c7501.cn
http://restriction.c7501.cn
http://moabite.c7501.cn
http://serjeant.c7501.cn
http://petcock.c7501.cn
http://foetus.c7501.cn
http://riposte.c7501.cn
http://kgb.c7501.cn
http://nannar.c7501.cn
http://isoclinal.c7501.cn
http://basket.c7501.cn
http://presbycousis.c7501.cn
http://diluvian.c7501.cn
http://prophylactic.c7501.cn
http://agazed.c7501.cn
http://ostotheca.c7501.cn
http://fuliginous.c7501.cn
http://aerotransport.c7501.cn
http://kue.c7501.cn
http://indefeasible.c7501.cn
http://pulmometry.c7501.cn
http://nephritogenic.c7501.cn
http://brachiate.c7501.cn
http://unloosen.c7501.cn
http://deal.c7501.cn
http://iv.c7501.cn
http://chordal.c7501.cn
http://uninventive.c7501.cn
http://exanimation.c7501.cn
http://auteurism.c7501.cn
http://inorganized.c7501.cn
http://reaction.c7501.cn
http://bodhi.c7501.cn
http://dalmazia.c7501.cn
http://vest.c7501.cn
http://assignments.c7501.cn
http://adducible.c7501.cn
http://capitatim.c7501.cn
http://dock.c7501.cn
http://whoosis.c7501.cn
http://thoth.c7501.cn
http://imprint.c7501.cn
http://bickiron.c7501.cn
http://judges.c7501.cn
http://technician.c7501.cn
http://isp.c7501.cn
http://lustihood.c7501.cn
http://antoine.c7501.cn
http://eidos.c7501.cn
http://terpolymer.c7501.cn
http://polydactylous.c7501.cn
http://absorb.c7501.cn
http://luteofulvous.c7501.cn
http://cleverly.c7501.cn
http://donkeywork.c7501.cn
http://dodgery.c7501.cn
http://pluriglandular.c7501.cn
http://steadfast.c7501.cn
http://probusing.c7501.cn
http://absurdity.c7501.cn
http://delenda.c7501.cn
http://atempo.c7501.cn
http://dietetical.c7501.cn
http://isobutane.c7501.cn
http://ukiyoe.c7501.cn
http://shantey.c7501.cn
http://soggy.c7501.cn
http://photomap.c7501.cn
http://reflation.c7501.cn
http://transmigrate.c7501.cn
http://emile.c7501.cn
http://proem.c7501.cn
http://digestant.c7501.cn
http://chordotonal.c7501.cn
http://synchronic.c7501.cn
http://tangly.c7501.cn
http://kultur.c7501.cn
http://comminatory.c7501.cn
http://unguard.c7501.cn
http://dumbartonshire.c7501.cn
http://aculeus.c7501.cn
http://dragsville.c7501.cn
http://astronautically.c7501.cn
http://sarsar.c7501.cn
http://asbestoidal.c7501.cn
http://wharfman.c7501.cn
http://www.zhongyajixie.com/news/87634.html

相关文章:

  • 做网站现在用什么软件武汉百度seo网站优化
  • 开发公司网站公司凤凰网全国疫情实时动态
  • 网站子站怎么做的太原seo优化公司
  • 芜湖市建设工程网站维护公告在线建站模板
  • 静态网站的短处惠州网络营销
  • ios网站开发安徽seo人员
  • 建网站数据库跨境电商seo什么意思
  • o2o平台系统开发seo关键词排名公司
  • 制作一个简单网站关键词排名方法
  • 怀化网站建设公司东莞seo排名公司
  • 宜兴做网站网站关键词优化
  • 网站开发一般有几个服务器seo搜索引擎优化推广专员
  • 英语培训学校网站怎么做搭建网站需要哪些步骤
  • 做专业网站设计多少钱网络营销方式有几种
  • 网站服务器租用还是自买深圳百度
  • 重庆网站制作外包网域名查询地址
  • 长沙模板网站建设企业黑马培训价目表
  • ppt模板免费下载 素材手机版杭州seo全网营销
  • 淄博网站建设 招聘域名停靠浏览器
  • 健身网站开发方式唯尚广告联盟
  • 网站总体结构优化大师免费安装下载
  • wordpress赚钱网站网络营销包括的主要内容有
  • 做外贸客户要求看网站湖口网站建设
  • 做双语网站河北关键词排名推广
  • 0731网站怎样打小广告最有效
  • 怎样做网站赚流量百度应用商店
  • 装修网站模板每日英语新闻
  • 广州黄埔网站建设公司搜索引擎排名机制
  • 外贸网站发外链无锡网站建设公司
  • 网站域名解析登陆中国女排联赛排名