c*****e 发帖数: 737 | 1 1, class A {virtual void f();}
class B:public A {};
class C:public B {};
class D:public A, B {virtual void f();}
让你说明D的virutal table
2, class A
{public:
A(int v) {var = v;}
void f(){cout << var << endl;}
int var;
}
class B:public A
{
public:
public B(int v1, v2){var = v1; var2 = v2;}
void f()
{cout << var << "," << var2 << endl;}
int var, var2;
}
main()
{
B* pb = static_cast(new A(1);
pb->f();
}
问你编译/运行会不会出错,出啥错。
3, atoi写程序,要返回错误代码,并且处理溢出。 | q********c 发帖数: 1774 | 2 Onsite or phone? They don't look like microsoft style question.Normally,
they would focus on data structures and algorithms. Which team ? | p*i 发帖数: 411 | 3 第一题的virtual table应该是啥样的?
我想的是
class D
vtable (A)
+0 D:f(); // (D*)->f() evaluates to this
vtable (B)
+0 A:f(); // (D*)->B::f() evaluates to this
(D*)->A::f() is ambiguous
第2题要么给A定义一个不带参数的ctor,要么在B的ctor中explicitly call A's ctor
还有最后static_cast(B)应该改成 static_cast(B*)
static_cast(B)(new A(1))会去找B的接受一个A*参数的ctor(不存在),而且返回的不是指针
【在 c*****e 的大作中提到】![](/moin_static193/solenoid/img/up.png) : 1, class A {virtual void f();} : class B:public A {}; : class C:public B {}; : class D:public A, B {virtual void f();} : 让你说明D的virutal table : 2, class A : {public: : A(int v) {var = v;} : void f(){cout << var << endl;} : int var;
|
|