-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
关于 pair 数据结构的相关构造函数的疑问? #119
Comments
首先这不是复制构造函数。 两个重载所要表达的是:如果 这种设计的目的是避免意外地引入“使用隐式转换的方式进行了本来要求为显式的转换”,参见 N4387 。 |
萌新求问大佬,为什么要用U替换掉Ty,直接用Ty不是也可以判断是否可以拷贝构造吗?还有pair参数是Ty,U不是一定等于Ty吗,为什么还要判断是否可以隐式转换呢?
|
|
非常感谢大佬的回答!如拨云见日,茅塞顿开!让我自己怎么也想不出来😂 所以我自己也试了一下,写了一个简单的例子,如果没有用U替换Ty的话,即使没用到这个函数(下面类A中的f)也会编译报错
|
对于已经定义了下面的copy构造函数:
为什么还要定义explicit的copy构造函数:
我理解模板参数的含义,就是不知道为什么这样定义,或者可以指出在什么情况下才会调用下面的 explicit的copy构造函数吗。谁能帮忙解答下?谢谢。
The text was updated successfully, but these errors were encountered: