关于隐式声明的复制构造函数的引用在逻辑上不清楚
The quote about implicitly-declared copy constructor is unclear on logic
The implicitly-declared copy constructor for a class X will have the form
X::X(const X&)
如果class类型M(或其数组)的每个可能构造的子对象都有一个复制构造函数,其第一个参数是const M&
或const volatile M&
类型
否则,隐式声明的复制构造函数的形式为
X::X(X&)
我想到这句话,逻辑可以转化为:
It's my box if each red card in this box has a shape of circle, otherwise it's jack's.
所以,我搜索了这个盒子,发现这个盒子里根本没有任何红牌。因此,这个盒子是我的还是杰克的?我认为这是一个模棱两可的提议。这是一个典型的逻辑问题。
class A{
int b;
};
int main(){
A a; //A::A(A&) or A::A(A const&) ?
}
即,问题也可以转化为:
//For this condition, A is either 0 or 1, Now I set A = 2
if(all(A) == 0){
then A belong to you
}else {
then A belong to mine
}
when there's no A in the set. A belong to mine?
我想把句子改成这样:
如果存在任何可能构造的class类型M(或其数组)的子对象都有一个复制构造函数,其第一个参数不是 类型的 const M& 或 const volatile M&,class X 的隐式声明的复制构造函数将具有以下形式:
X::X(X&)
否则,隐式声明的复制构造函数将具有以下形式:
X::X(const X&)
这样就更清楚了。
if(exsit(A)!=1){
then A will belong to you
}else{
A will belong to mine
}
所以,对于A
,只要存在A
A的值不为1,就是第一个分支,否则就是第二个分支,不存在一个 A 的值,使得没有分支可以匹配它或不明确。
这两个公式是完全等价的。标准语句的形式为 if(all P) then A else B
,而建议的重新语句只是 if(exist non-P) then B else A
,逻辑上相同。
提出的问题归结为当集合 all P
为空时它是如何工作的,即 class X
没有“ [=] 的潜在构造子对象34=] 类型(或其数组)”。在那种情况下 if(all P)
是 vacuously true,因此 A
适用。换句话说,class X
的隐式声明的复制构造函数没有潜在构造的 class 类型(或其数组)的子对象的形式为 X::X(const X&)
.
附带说明一下,“空洞的真理”的概念听起来有点像逻辑诡辩,但它经常以不同的形式使用。对于 C++ 示例:
bool IsAllPositive(vector<int> const &v)
{
for(auto n : v)
if(n <= 0) return false;
return true;
}
这个 returns true
如果向量是空的,在那种情况下确实 IsAllPositive
是空洞的。
The implicitly-declared copy constructor for a class X will have the form
X::X(const X&)
如果class类型M(或其数组)的每个可能构造的子对象都有一个复制构造函数,其第一个参数是
类型const M&
或const volatile M&
否则,隐式声明的复制构造函数的形式为
X::X(X&)
我想到这句话,逻辑可以转化为:
It's my box if each red card in this box has a shape of circle, otherwise it's jack's.
所以,我搜索了这个盒子,发现这个盒子里根本没有任何红牌。因此,这个盒子是我的还是杰克的?我认为这是一个模棱两可的提议。这是一个典型的逻辑问题。
class A{
int b;
};
int main(){
A a; //A::A(A&) or A::A(A const&) ?
}
即,问题也可以转化为:
//For this condition, A is either 0 or 1, Now I set A = 2
if(all(A) == 0){
then A belong to you
}else {
then A belong to mine
}
when there's no A in the set. A belong to mine?
我想把句子改成这样:
如果存在任何可能构造的class类型M(或其数组)的子对象都有一个复制构造函数,其第一个参数不是 类型的 const M& 或 const volatile M&,class X 的隐式声明的复制构造函数将具有以下形式:
X::X(X&)
否则,隐式声明的复制构造函数将具有以下形式:
X::X(const X&)
这样就更清楚了。
if(exsit(A)!=1){
then A will belong to you
}else{
A will belong to mine
}
所以,对于A
,只要存在A
A的值不为1,就是第一个分支,否则就是第二个分支,不存在一个 A 的值,使得没有分支可以匹配它或不明确。
这两个公式是完全等价的。标准语句的形式为 if(all P) then A else B
,而建议的重新语句只是 if(exist non-P) then B else A
,逻辑上相同。
提出的问题归结为当集合 all P
为空时它是如何工作的,即 class X
没有“ [=] 的潜在构造子对象34=] 类型(或其数组)”。在那种情况下 if(all P)
是 vacuously true,因此 A
适用。换句话说,class X
的隐式声明的复制构造函数没有潜在构造的 class 类型(或其数组)的子对象的形式为 X::X(const X&)
.
附带说明一下,“空洞的真理”的概念听起来有点像逻辑诡辩,但它经常以不同的形式使用。对于 C++ 示例:
bool IsAllPositive(vector<int> const &v)
{
for(auto n : v)
if(n <= 0) return false;
return true;
}
这个 returns true
如果向量是空的,在那种情况下确实 IsAllPositive
是空洞的。