f*******y 发帖数: 988 | 1 【 以下文字转载自 Quant 讨论区 】
发信人: yayadoudou (yayadou), 信区: Quant
标 题: 问个面试问题,请教
发信站: BBS 未名空间站 (Fri Jun 20 14:05:58 2008)
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 |
f*******y 发帖数: 988 | 2 帮你转这里,呵呵
【在 f*******y 的大作中提到】 : 【 以下文字转载自 Quant 讨论区 】 : 发信人: yayadoudou (yayadou), 信区: Quant : 标 题: 问个面试问题,请教 : 发信站: BBS 未名空间站 (Fri Jun 20 14:05:58 2008) : 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
|
O*********y 发帖数: 633 | 3 I assume you will compile the lib into dll not static lib file.
My answer might be wrong but in this case I will choose C. change destructor
into virtual.
The reason is in the run time, other library based on this class may try to
find a non-virtual destructor directly instead of look up a vtable because
the class user wasn't given information that the destructor now is virtual.
Please correct me if I am wrong. |
v**u 发帖数: 20 | 4 My answer is b, add data member changed object type, it requires all
dependent library. |
f******y 发帖数: 2971 | |
s******e 发帖数: 431 | 6 如果这个data member 加在最后, 应该也没有影响。我选C
【在 f******y 的大作中提到】 : 我选b,因为b可能需要DA。
|
s*****d 发帖数: 43 | 7 Are we limited to only 1 answer?
b, c, d
d is in because the caller of this function will have to recompile and
relink. |
n**d 发帖数: 9764 | 8 It depends on how many libraries the application uses too. At least the
libraries used by this application need to be re-built.
function
【在 f*******y 的大作中提到】 : 帮你转这里,呵呵
|
s*******d 发帖数: 59 | 9 c++,c#,java Object Memory Layout,哪儿有详细资料吗? |
O*********y 发帖数: 633 | 10 After some tests, the answer looks like to be B, C and D.
Something worth mention:
For C, if add a data member after the last existing declared data member,
libs depending on this class may not need to be re-compiled. If the newly
added data member is inserted between two existing data member declaration,
libs depending on this class need to be re-compiled.
for D, if add a arguments and assign a default value to it, all derived libs
need to be re-compiled. |
s*******d 发帖数: 59 | 11 添加一个member在最后,虽然能link,但并不等于没问题。
lib里分配的内存大小是错的。 |
M**8 发帖数: 25 | 12 This post is cross posted. Should mention it in the initial post, IMHO.
http://www.mitbbs.com/article_t/Computation/31159531.html |
O*******d 发帖数: 20343 | 13 Adding a member may change the size of an object, requiring recompilation of
all code that use this class.
,
libs
【在 O*********y 的大作中提到】 : After some tests, the answer looks like to be B, C and D. : Something worth mention: : For C, if add a data member after the last existing declared data member, : libs depending on this class may not need to be re-compiled. If the newly : added data member is inserted between two existing data member declaration, : libs depending on this class need to be re-compiled. : for D, if add a arguments and assign a default value to it, all derived libs : need to be re-compiled.
|