a****l 发帖数: 245 | 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 |
J******d 发帖数: 506 | 2 Someone asked this question before.
function
【在 a****l 的大作中提到】 : 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**u 发帖数: 1567 | 3 c
function
【在 a****l 的大作中提到】 : 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
|
a****l 发帖数: 245 | 4 忘说了,我也记得有人问过了,当时没在意,又找不到帖子,所以发了新帖
【在 J******d 的大作中提到】 : Someone asked this question before. : : function
|
a****l 发帖数: 245 | 5 能否具体解释下?
【在 r**u 的大作中提到】 : c : : function
|
a****n 发帖数: 1887 | 6 都需要。。
a. add a constructor
如果class只有default constructor, 加入新的constructor, client code
A a; 就不work了
b. add a data member
class layout 改变, 肯定要重新编译,
c. change destructor into virtual
如果原class 没有vtable, 这个会改变class layout
d. add an argument with default value to an existing member function
函数签名改变, 调用到该函数的程序,需要重新编译 |
c****p 发帖数: 32 | 7 嗯,但是也可以从另一个方面来说不需要recompile.
如果已经explicitly 有了其他ctor,加入新的没有影响。
这个基本上是要重新compile,一个例外是加入原来的class本来就只是method的封装比
如:
class Methods
{
public:
staic void test1();
}
这样加入new member fields也没什么关系(但是如果client code有类似sizeof(
Methods)的就不行)
这个一定要重新compile.其他的例子都可以找到反例(虽然有点急转弯的意思),但是
因为dtor是一定要被用到的,如果原本的dtor变成virtual,那么client端整个调用过
程就变了。原来是:
$Class_Dtor();
变成virtual后变成了
pClass->vtbl[index_of_dtor]();
所以client端必须重新compile.
反例是如果这个member function根本就没用到:D
【在 a****n 的大作中提到】 : 都需要。。 : a. add a constructor : 如果class只有default constructor, 加入新的constructor, client code : A a; 就不work了 : b. add a data member : class layout 改变, 肯定要重新编译, : c. change destructor into virtual : 如果原class 没有vtable, 这个会改变class layout : d. add an argument with default value to an existing member function : 函数签名改变, 调用到该函数的程序,需要重新编译
|
a****l 发帖数: 245 | |