由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Quant版 - a c++ interview question
相关主题
问个面试问题,请教问个C++的问题
[合集] JP Morgan 面试之前要做一个online 的C++ test?C++ 110 题在精华区怎么找不到?
[合集] Renaissance电话面世经验分享on-site经验
[合集] 高盛 C++ 面试题[合集] 分享on-site经验
某某 trading 的一道题[合集] ok, not so short phone interview
也问一个题--C++about copy-constructor
C++ online Test 2题码题
问一个c++的问题when will you want to use a virtual constructor?
相关话题的讨论汇总
话题: libraries话题: class话题: add话题: data
进入Quant版参与讨论
1 (共1页)
w******l
发帖数: 58
1
You have a class that many libraries depend on. Now you need to modify the c
lass 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
s*****g
发帖数: 323
2
I think b.
maybe also c, although I am not sure

c
recompiling

【在 w******l 的大作中提到】
: You have a class that many libraries depend on. Now you need to modify the c
: lass 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

S*********g
发帖数: 5298
3
IB's problem ba

c
recompiling

【在 w******l 的大作中提到】
: You have a class that many libraries depend on. Now you need to modify the c
: lass 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

w******l
发帖数: 58
4
yeah.
not 100% sure about the answer.
what's yours?

【在 S*********g 的大作中提到】
: IB's problem ba
:
: c
: recompiling

s*****I
发帖数: 23
5
B
without recompiling, the object size will be inconsistent between libs.
It is a common problem in real world.

c
recompiling

【在 w******l 的大作中提到】
: You have a class that many libraries depend on. Now you need to modify the c
: lass 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

i**h
发帖数: 17
6
a. e.g. if you had no constructor defined before and now you added new ones.
b. obvious...
c. if the class didn't have any virtual method before, it now has a v-table
which could shift the offsets of its data members

c
recompiling

【在 w******l 的大作中提到】
: You have a class that many libraries depend on. Now you need to modify the c
: lass 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**m
发帖数: 102
7
why is b. obvious?

ones.
table

【在 i**h 的大作中提到】
: a. e.g. if you had no constructor defined before and now you added new ones.
: b. obvious...
: c. if the class didn't have any virtual method before, it now has a v-table
: which could shift the offsets of its data members
:
: c
: recompiling

A***l
发帖数: 302
8
It changes the size of the class.

【在 a**m 的大作中提到】
: why is b. obvious?
:
: ones.
: table

m********0
发帖数: 2717
9
also a. Consider the following.
Adding an overloading constructor does matter in this case.
#include
using std::cout; using std::endl;
class a{
public:
a(int val): data(val){}
//a(double val): data(val){}
void getData(){cout << data << endl;}
private:
double data;
};
int main()
{
a aa(1.1);
aa.getData();
return 0;
}

the c
recompiling

【在 w******l 的大作中提到】
: You have a class that many libraries depend on. Now you need to modify the c
: lass 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

m*********y
发帖数: 127
10
纯借id发文……
我以前选的是d,主要是从能否成功build的角度看的……

c
recompiling
各库都已经编译过,即使增加新的constructor,导致如重载的变化、默认构造函数无
效,但是应该都会保留原有的行为,不会导致链接失败。
同意前面的,这个导致memory layout变化,确实会影响行为,带来很多不安全的因素
。但是应该也不会导致链接失败。
同意前面的,如果以前没有虚函数,现在会增加vtable,同样改变了memory layout…
…但是其他情况下,应该行为都没有变化,并且链接不会失败。
C++/C里面函数默认值应该是静态绑定的,增加默认参数仍然改变了函数的signature,
如果库里有调用的话,应该会导致链接失败

【在 w******l 的大作中提到】
: You have a class that many libraries depend on. Now you need to modify the c
: lass 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

相关主题
也问一个题--C++问个C++的问题
C++ online Test 2题C++ 110 题在精华区怎么找不到?
问一个c++的问题分享on-site经验
进入Quant版参与讨论
w******l
发帖数: 58
11
yes, i guess abcd all have their problems.
not sure what the problem means by need to recompile...
does it mean that there will be no link problems, or
does it mean that the program need to be recompiled to
give the correct result.

【在 m*********y 的大作中提到】
: 纯借id发文……
: 我以前选的是d,主要是从能否成功build的角度看的……
:
: c
: recompiling
: 各库都已经编译过,即使增加新的constructor,导致如重载的变化、默认构造函数无
: 效,但是应该都会保留原有的行为,不会导致链接失败。
: 同意前面的,这个导致memory layout变化,确实会影响行为,带来很多不安全的因素
: 。但是应该也不会导致链接失败。
: 同意前面的,如果以前没有虚函数,现在会增加vtable,同样改变了memory layout…

J******d
发帖数: 506
12
应该假设对这个class的改变本身不会造成问题吧。否则,ABCD项乱搞的话都能出错。
光考虑linkage的话,我觉得Mitbbshoney说的是正解。

【在 w******l 的大作中提到】
: yes, i guess abcd all have their problems.
: not sure what the problem means by need to recompile...
: does it mean that there will be no link problems, or
: does it mean that the program need to be recompiled to
: give the correct result.

m********0
发帖数: 2717
13

我觉得这取决于出题者到底想考察什么?我记得原体是不重新编译对建立在原LIB上的
程序安全与否。
如果重载变化,可能应用程序在新旧LIB上有不同的定义,而且旧应用程序会调用新添
加的重载函数,这就不安全了。 总之,看怎么理解题目了。 记得题目是问需不需要
recompile。而不是recompile能不能成功build。

【在 m*********y 的大作中提到】
: 纯借id发文……
: 我以前选的是d,主要是从能否成功build的角度看的……
:
: c
: recompiling
: 各库都已经编译过,即使增加新的constructor,导致如重载的变化、默认构造函数无
: 效,但是应该都会保留原有的行为,不会导致链接失败。
: 同意前面的,这个导致memory layout变化,确实会影响行为,带来很多不安全的因素
: 。但是应该也不会导致链接失败。
: 同意前面的,如果以前没有虚函数,现在会增加vtable,同样改变了memory layout…

S*********r
发帖数: 42
14
C. I would say that.
Let's say in the ClassA.h file:
class A
{
A() {}
}
In the library's LibB.h:
class A;
class B
{
A *m_pA;
}
In the LibB.cpp
#include "ClassA.h"
void B::B()
{
m_pA = 0;
}
In other libraries Others.cpp, we have
#include "LibB.h"
....
In this case, such changes as a, b and d do not require recompiling other
libraries, though relinking is required. However, the change as c requires
recompiling all the dependent libraries since the virtual table is created.

c
recompiling

【在 w******l 的大作中提到】
: You have a class that many libraries depend on. Now you need to modify the c
: lass 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
15
你试过D没有?
D是唯一一个必须要recompile的,否则linking一定会找不到reference symbol

【在 S*********r 的大作中提到】
: C. I would say that.
: Let's say in the ClassA.h file:
: class A
: {
: A() {}
: }
: In the library's LibB.h:
: class A;
: class B
: {

t**********t
发帖数: 1
16
前辈,
请问在电面里问了些什么\,可以指教一下吗? &#
36824;有,你报的职位是 trader 还是 quant researcher? 我&#
25253;了几十间公司,只有这一间有回音,很想知道是怎么\&#
26679;的地方。 非常感谢。
d*j
发帖数: 13780
17
.......
niu

【在 t**********t 的大作中提到】
: 前辈,
: 请问在电面里问了些什么\,可以指教一下吗? &#
: 36824;有,你报的职位是 trader 还是 quant researcher? 我&#
: 25253;了几十间公司,只有这一间有回音,很想知道是怎么\&#
: 26679;的地方。 非常感谢。

m********0
发帖数: 2717
18
好多乱码。IB还是这么活跃,我恨他们。
1 (共1页)
进入Quant版参与讨论
相关主题
when will you want to use a virtual constructor?某某 trading 的一道题
这句code什么意思?也问一个题--C++
问个面试问题,请教C++ online Test 2题
问个C++重新编译的问题问一个c++的问题
问个面试问题,请教问个C++的问题
[合集] JP Morgan 面试之前要做一个online 的C++ test?C++ 110 题在精华区怎么找不到?
[合集] Renaissance电话面世经验分享on-site经验
[合集] 高盛 C++ 面试题[合集] 分享on-site经验
相关话题的讨论汇总
话题: libraries话题: class话题: add话题: data