码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • C++函数在重载时如何判断函数签名(function signature)是否相同


    Argument Type Differences

    参数类型区别

    (以下根据MSDN整理而成)
    Overloaded functions differentiate between argument types that take different initializers. Therefore, an argument of a given type and a reference to that type are considered the same for the purposes of overloading. They are considered the same because they take the same initializers. For example, max( double, double ) is considered the same as max( double &, double & ). Declaring two such functions causes an error.
    重载函数根据不同的参数初始化方式区分函数。因此,某个类型的参数和这个类型的引用参数被认为一样的,因为他们的初始化方式一致。所以,max( double, double ) 被认为和max( double &, double & ).一样。

    For the same reason, function arguments of a type modified by const or volatile are not treated differently than the base type for the purposes of overloading.
    同样原因,某个类型的参数和这个类型的const参数也认为是一样的。

    However, the function overloading mechanism can distinguish between references that are qualified by const and volatile and references to the base type. This makes code such as the following possible:
    不过,函数重载机制可以区分引用和const、volatile引用。因此,下面代码可行。

    // argument_type_differences.cpp
    // compile with: /EHsc /W3
    // C4521 expected
    #include <iostream>
    
    using namespace std;
    class Over {
    public:
       Over() { cout << "Over default constructor\n"; }
       Over( Over &o ) { cout << "Over&\n"; }
       Over( const Over &co ) { cout << "const Over&\n"; }
       Over( volatile Over &vo ) { cout << "volatile Over&\n"; }
    };
    
    int main() {
       Over o1;            // Calls default constructor.
       Over o2( o1 );      // Calls Over( Over& ).
       const Over o3;      // Calls default constructor.
       Over o4( o3 );      // Calls Over( const Over& ).
       volatile Over o5;   // Calls default constructor.
       Over o6( o5 );      // Calls Over( volatile Over& ).
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    Pointers to const and volatile objects are also considered different from pointers to the base type for the purposes of overloading.
    另外,指针和const、volatile指针也被认为是不一样的。
    总结一句话,重载时根据函数参数数量、类型进行区分,当const、volatile限定引用和指针类型的参数时,也可做区分的依据。

  • 相关阅读:
    无人机影像的空间三维建模:Pix4Dmapper运动结构恢复法
    Arduino驱动MAX31865读取铂电阻温度
    Android seekbar使用
    Shell入门笔记:Linux批量提取文件名/shel文件名提取日期/NCL批量读取文件(shell脚本结合)
    向excel中导入mysql中的数据表
    【C++进阶:多态】多态的构成条件 | 虚函数的重写 | 抽象类 | 多态的原理 | 多继承的虚函数表
    一块GPU搞定ChatGPT;ML系统入坑指南;理解GPU底层架构
    Win7 搭建NodeJs、Vue2、Vue3,基于 vue-cli 创建建vue工程及相关问题解决思路
    java计算机毕业设计健身房管理系统演示录像2021源码+mysql数据库+系统+lw文档+部署
    大数据课程M1——ELK的概述
  • 原文地址:https://blog.csdn.net/mary288267/article/details/124908900
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号