z****e 发帖数: 2024 | 1 You have a class that many libraries depend on. Now you need to modify the
class for one application. Which of the following changes require
recompiling
all libraries before it is safe to build the application?
a. add a constructor
b. add a data member
c. change destructor into virtual
d. add an argument with default value to an existing member function |
x****u 发帖数: 44466 | 2 c和d啊,b最好也重新编译,depends。
【在 z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : You have a class that many libraries depend on. Now you need to modify the : class for one application. Which of the following changes require : recompiling : all libraries before it is safe to build the application? : a. add a constructor : b. add a data member : c. change destructor into virtual : d. add an argument with default value to an existing member function
|
z****e 发帖数: 2024 | 3 c,我觉得好像不需要啊。
【在 x****u 的大作中提到】![](/moin_static193/solenoid/img/up.png) : c和d啊,b最好也重新编译,depends。
|
z****e 发帖数: 2024 | 4 而且感觉这个题目具体的问题不是很清楚。
如果是链接旧的库,在旧的库不重新编译的情况下,重载的ctor会找不到定义,而更改
的那个函数本身签名就变了,a,d,必须重新编译旧库,不然无法链接啊。 |
x****u 发帖数: 44466 | 5 需要啊,改变了类的虚构行为,不重编译在旧代码里不会生效。
【在 z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : c,我觉得好像不需要啊。
|
z****e 发帖数: 2024 | 6 那岂不abcd都需要重新编译了?
这题目到底什么意思呢。
【在 x****u 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 需要啊,改变了类的虚构行为,不重编译在旧代码里不会生效。
|
P********e 发帖数: 2610 | 7 all
with a constructor, compiler may not need to synthsize.
data size changes
add virtual
overloadding, function pointer offset may changes.
【在 z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : You have a class that many libraries depend on. Now you need to modify the : class for one application. Which of the following changes require : recompiling : all libraries before it is safe to build the application? : a. add a constructor : b. add a data member : c. change destructor into virtual : d. add an argument with default value to an existing member function
|
x****u 发帖数: 44466 | 8 A不需要啊,如果原来有个constructor,又加了一个的话。
【在 z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 那岂不abcd都需要重新编译了? : 这题目到底什么意思呢。
|
P********e 发帖数: 2610 | 9 需要
class A {
A(int i){}
// virtual foo()
};
A a;
上面code,如果A变成了
class A {
A(int i){}
A(){}
// virtual foo()
}
synthsized constructor is nontrivial
【在 x****u 的大作中提到】![](/moin_static193/solenoid/img/up.png) : A不需要啊,如果原来有个constructor,又加了一个的话。
|
r****t 发帖数: 10904 | 10 再 zkss? 这么改了以后用戶 code 用的 A(int i) 没变,也没有必要改动啊?为啥需要重新编译?当然我只是说源码不用改,linking 需要重新来,是不是 link 时候 name mangling 有变化必须重新编译呢?
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 需要 : class A { : A(int i){} : // virtual foo() : }; : A a; : 上面code,如果A变成了 : class A { : A(int i){} : A(){}
|
|
|
r****t 发帖数: 10904 | 11 这个不是问是不是生效吧,是问是不是 safe,不一定要生效,只要能 work, defined
就行吧。
【在 x****u 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 需要啊,改变了类的虚构行为,不重编译在旧代码里不会生效。
|
x****u 发帖数: 44466 | 12 你说的对,他这个例子不恰当。
【在 r****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 再 zkss? 这么改了以后用戶 code 用的 A(int i) 没变,也没有必要改动啊?为啥需要重新编译?当然我只是说源码不用改,linking 需要重新来,是不是 link 时候 name mangling 有变化必须重新编译呢?
|
x****u 发帖数: 44466 | 13 前一种情况也没有trivial的constructor生成。
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 需要 : class A { : A(int i){} : // virtual foo() : }; : A a; : 上面code,如果A变成了 : class A { : A(int i){} : A(){}
|
X****r 发帖数: 3557 | 14 The question is not clear enough. There are two way to define 'safe'
here:
1. The behavior of only recompiling the application without
recompiling the library is the same as recompiling everything.
2. The behavior of the library without recompiling when linked
together with the recompiled application is the same as the behavior
of the library before the change of the class.
The original question probably intended (2), but the language does
not explicitly refute (1), in which case none of the opt
【在 z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : You have a class that many libraries depend on. Now you need to modify the : class for one application. Which of the following changes require : recompiling : all libraries before it is safe to build the application? : a. add a constructor : b. add a data member : c. change destructor into virtual : d. add an argument with default value to an existing member function
|
r****t 发帖数: 10904 | 15 还是这个表达的清楚。我以为 safe 一般默认就是 defined,
【在 X****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : The question is not clear enough. There are two way to define 'safe' : here: : 1. The behavior of only recompiling the application without : recompiling the library is the same as recompiling everything. : 2. The behavior of the library without recompiling when linked : together with the recompiled application is the same as the behavior : of the library before the change of the class. : The original question probably intended (2), but the language does : not explicitly refute (1), in which case none of the opt
|
t****t 发帖数: 6806 | 16 i remember the questions being asked quite a few times here, we agreed none
of the answers are guaranteed to be safe. but i think originally the intenti
on is (2)(3)(4) as i remember the original question is which one does NOT re
quire recompile everything...when we had an explicit ctor defined, (1) indee
d does not require recompiling, in which case the original behaviour would b
e kept intact.
【在 X****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : The question is not clear enough. There are two way to define 'safe' : here: : 1. The behavior of only recompiling the application without : recompiling the library is the same as recompiling everything. : 2. The behavior of the library without recompiling when linked : together with the recompiled application is the same as the behavior : of the library before the change of the class. : The original question probably intended (2), but the language does : not explicitly refute (1), in which case none of the opt
|
X****r 发帖数: 3557 | 17 Yes, the original question probably meant (2)(3)(4).
none
intenti
NOT re
indee
would b
【在 t****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : i remember the questions being asked quite a few times here, we agreed none : of the answers are guaranteed to be safe. but i think originally the intenti : on is (2)(3)(4) as i remember the original question is which one does NOT re : quire recompile everything...when we had an explicit ctor defined, (1) indee : d does not require recompiling, in which case the original behaviour would b : e kept intact.
|
P********e 发帖数: 2610 | 18 我还是决的1应该需要啊
if we add a nontrivial ctor,in cases, compiler doesn't need to synthesize
ctor
we need to recompile, right?
【在 X****r 的大作中提到】![](/moin_static193/solenoid/img/up.png) : Yes, the original question probably meant (2)(3)(4). : : none : intenti : NOT re : indee : would b
|
t****t 发帖数: 6806 | 19 read my post again, i said "when we had an explicit ctor defined"
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 我还是决的1应该需要啊 : if we add a nontrivial ctor,in cases, compiler doesn't need to synthesize : ctor : we need to recompile, right?
|
r****t 发帖数: 10904 | 20 wow, 你说话是滴水不漏啊。你面别人都要说话这么严格的,岂不是大部分都挂了。
【在 t****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : read my post again, i said "when we had an explicit ctor defined"
|
|
|
P********e 发帖数: 2610 | 21 就算已经有一个ctro定义了,我们加一个新的ctor
compiler还是可能不需要synthesize的情况不变啊
【在 t****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : read my post again, i said "when we had an explicit ctor defined"
|
z****e 发帖数: 2024 | 22 我经过实践的检验,
a. add a constructor
b. add a data member
c. change destructor into virtual
d. add an argument with default value to an existing member function
a, 肯定没有问题。
b, link, run 都没发现问题,应该是我的例子还不够好。正在苦想例子。
c, 是runtime 崩溃,情理之中。
d, 如果不给新的定义,则link出错,情理之中。如果给新定义,则原来旧库的同名函
数被hide,下面link,run都没问题。不出现经典的overload 报错。g++4.2 |
z****e 发帖数: 2024 | 23 加一个新的就是overload一个版本,只要你link这个新的库,和旧的库,一起,就没问
题。不论是不是explicit。
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 就算已经有一个ctro定义了,我们加一个新的ctor : compiler还是可能不需要synthesize的情况不变啊
|
r****t 发帖数: 10904 | 24
试试 client code side declare 一个 array。或者是有啥 sizeof 的操作。
【在 z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 我经过实践的检验, : a. add a constructor : b. add a data member : c. change destructor into virtual : d. add an argument with default value to an existing member function : a, 肯定没有问题。 : b, link, run 都没发现问题,应该是我的例子还不够好。正在苦想例子。 : c, 是runtime 崩溃,情理之中。 : d, 如果不给新的定义,则link出错,情理之中。如果给新定义,则原来旧库的同名函 : 数被hide,下面link,run都没问题。不出现经典的overload 报错。g++4.2
|
r****t 发帖数: 10904 | 25 其实我不太懂你说的 “不需要synthesize”是啥意思。。。
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 就算已经有一个ctro定义了,我们加一个新的ctor : compiler还是可能不需要synthesize的情况不变啊
|
z****e 发帖数: 2024 | 26 b,也被检验出问题。我的例子还是link可以成功,但是运行结果错误。
至此,
b,c,d,都各自有不同的问题,只有a,还没有问题。
【在 z****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 我经过实践的检验, : a. add a constructor : b. add a data member : c. change destructor into virtual : d. add an argument with default value to an existing member function : a, 肯定没有问题。 : b, link, run 都没发现问题,应该是我的例子还不够好。正在苦想例子。 : c, 是runtime 崩溃,情理之中。 : d, 如果不给新的定义,则link出错,情理之中。如果给新定义,则原来旧库的同名函 : 数被hide,下面link,run都没问题。不出现经典的overload 报错。g++4.2
|
t****t 发帖数: 6806 | 27 原来有ctor定义的话, compiler当然就不会自动生成ctor了
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 就算已经有一个ctro定义了,我们加一个新的ctor : compiler还是可能不需要synthesize的情况不变啊
|
t****t 发帖数: 6806 | 28 我是做EE的好不好, 不面写程序. 就算面EE, 我也很好说话的, 没见我给阿三那么多提
示吗...
【在 r****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : wow, 你说话是滴水不漏啊。你面别人都要说话这么严格的,岂不是大部分都挂了。
|
P********e 发帖数: 2610 | 29 我上面例子
【在 t****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 原来有ctor定义的话, compiler当然就不会自动生成ctor了
|
t****t 发帖数: 6806 | 30 例子来例子去, 哪里来的例子? 你是既无例子又无理由. 我说请你学好中文不是没有原
因的.
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 我上面例子
|
|
|
P********e 发帖数: 2610 | 31 你再想想
【在 t****t 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 原来有ctor定义的话, compiler当然就不会自动生成ctor了
|
z****e 发帖数: 2024 | 32 你再想想,真理往往掌握在为数不多的几个师傅们的手中。
我觉得你要理解一下这个题目的意思。
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 你再想想
|
t****t 发帖数: 6806 | 33 cf [12.1, clause 5]
【在 P********e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 你再想想
|