隐式声明和隐式定义的拷贝构造函数之间的区别是什么? [英] What is the distinction between implicitly-declared and implicitly-defined copy constructors?

查看:549
本文介绍了隐式声明和隐式定义的拷贝构造函数之间的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看复制构造函数的cppreference页面:
http://en.cppreference。 com / w / cpp / language / copy_constructor

I am reviewing the cppreference page on copy constructors here: http://en.cppreference.com/w/cpp/language/copy_constructor

我已经阅读了关于隐式声明的拷贝构造函数和隐式定义的拷贝构造函数的两节次,但我还是不明白的区别。不是一个隐式声明但是没有定义的构造函数导致链接器问题?

I've read the 2 sections regarding implicitly-declared copy constructors and implicitly-defined copy constructors quite a few times but I still don't understand the distinction. Wouldn't an implicitly declared but NOT defined constructor result in linker problems?

规则非常复杂。我不记得在C ++ 03有一个区别:你有一个编译器生成的复制构造函数或你没有。

The rules are very complex. I don't remember there being a distinction in C++03: Either you had a compiler generated copy constructor or you didn't.

有人可以解释这两个类别之间的区别是什么?

Can someone explain (in simpler words) what the distinction/differences are between these two categories?

推荐答案

第12条:


<类类型,当程序做
没有显式声明它们。如果它们是odr使用的(3.2),实现将隐式地定义它们。
见12.1,12.4和12.8。 - 结束注释]

C ++ 14(N3936)的规范引用为12.1 / 5,12.4 / 6,12.8 / 13,12.8 / 26。在每种情况下,相应的特殊成员函数是隐式定义的,如果它是默认的,并且没有定义为已删除,并且使用odr使用或显式默认。如果我们有类似

Normative references for C++14 (N3936) are 12.1/5, 12.4/6, 12.8/13, 12.8/26. In each case the corresponding special member function is implicitly defined if it is defaulted and not defined as deleted, and either odr-used or explicitly defaulted. If we have something like

struct Foo {};

且没有类型 Foo 的对象创建,所有六个特殊成员函数(默认构造函数,析构函数,复制构造函数,移动构造函数,复制赋值操作符,移动赋值操作符)都隐式声明为默认值,但不定义,因为它们不是odr使用的。

and no objects of type Foo are ever created, all six special member functions (default constructor, destructor, copy constructor, move constructor, copy assignment operator, move assignment operator) are implicitly declared as defaulted, but not defined since they are not odr-used.

这篇关于隐式声明和隐式定义的拷贝构造函数之间的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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