如何找出编译器生成的函数? [英] How to find out which functions the compiler generated?

查看:53
本文介绍了如何找出编译器生成的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解编译器生成的函数,三个规则和五个规则.在实际情况下,准确地找出编译器实际创建了哪些编译器生成的函数(构造函数,赋值运算符,析构函数)可能并不容易.

是否可以列出特定类的编译器生成的函数?

我主要对Visual Studio 2019和Xcode感兴趣,但更欢迎使用通用解决方案.

解决方案

规则很复杂.我将从另一个答案中窃取

这里的道理是,一个好的做法是不依赖,不依赖编译器的隐式声明,而是显式声明每个特殊成员(默认或删除,具体取决于您的需要)

I know about compiler-generated functions, the rule of three and the rule of five. In real-world scenarios, it may not be trivial to figure out exactly which of the compiler-generated functions (constructors, assignment operators, destructor) were actually created by the compiler.

Is there any way to list the compiler-generated functions for a specific class?

I am primarily interested in Visual Studio 2019 and Xcode, but a generic solution would be even more welcome.

解决方案

The rules are complicated. I will steal from another answer which quotes a table from Howard Hinnant's presentation.

The moral here is that a good practice is to not rely on compiler implicit declares and explicitly declare every special member (as defaulted or deleted, depending on your needs)

这篇关于如何找出编译器生成的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆