特殊成员函数是“如果使用它们,编译器将自动生成的函数,但没有由程序员显式声明”。
http://en.wikipedia.org/wiki/Special_member_functions
详细信息在 C++11 标准的第 12 节中:
The default constructor (12.1), copy constructor and copy assignment operator (12.8), move constructor and move assignment operator (12.8), and destructor (12.4) are special member functions. [Note: The implementation will implicitly declare these member functions for some class types when the program does not explicitly declare them. The implementation will implicitly define them if they are odr-used (3.2). See 12.1,12.4 and 12.8. —end note]
有哪些已知的方法可以在编译时识别所有生成的特殊成员函数?
我首选的编译器是 gcc 和 clang。
最佳答案
在 c++11 中, header <type_traits>
定义了一组以下函数:
is_constructible
is_default_contructible
is_copy_contructible
is_move_contructible
is_assignable
is_copy_assignable
is_move_assignable
is_destructible
您可以使用它们在编译时测试是否存在隐式生成的方法, 例如:
std::is_constructible<ClassName>::value
关于c++ - 识别自动生成的成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25821495/