日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Autodesk 的 c 題(2007.05) - 面試總結(jié) - 堅持到底

 ShaneWu 2009-12-08
Autodesk 的 c++題(2007.05)

1. What and why is explicit constructor and explicit copy constructor?

2. What the difference between Struct and Class?

3. What is vitrual function and why we need vtable?

1.

Explicit constructor and copy constructor is used to preventing implicit type cast.

An explicit constructor can not take part in implicit conversions. It can only be  used to explicit construct an object

Consider the Class below:

class A

{

public:

A();

A(int i);

A(A& a);

int i;

virtual ~A();

};

The following program will success to compile :

A a = 10;

or

A a;

a = 10;

because A has a constructor that accept a Int as a arguments

Those codes above are equal to

A tmp(10);    //constructor

a(tmp);      //copy constructor

or

A tmp(10) ;  //constructor

a = tmp;     // operator =

Note: explicit on a constructor with mutiple arguments has no effect,  unless all  but one of the arguments has a default value !

2: differences between struct and class?

3 difference between struct and class

1)members in struct are by default public while members in class are by default  private.

2)inhert  from  a struct is by default public , inhert from a class is by default private.

For example

struct A

{

};

struct B : (public)A

{

} ;

class A

{

};

class B: (private)A

{

};

3)class can be used as typename in template while struct can not

template(class T)      //right

template(struct T)     //wrong

3: What is virtual function and why we need vtable?

1) a virtual function is a function member of a class decleared with a virtual  keyword

2) it usually has a different functionality in the derived class

3) A function is resolved at run-time

The main difference between a non_virtual function and a virtual  function is, the  non_virtual function is resolved at compile time. This  mechanism is called  static_binding.  As the virtual function is  resolved at run time, This mechanism is  know as dynamic_binding

v_table is kind of lookup table.It contains pointers to the virtual  functions provided  by a class, and each object of the class contains a  pointer to its v_table(or  vtables, in some multiple-inheritance  situations)

A v_table is created at compile time,  so whether  a object is referenced by any  pointers or reference, when a virtual  fall happens, the v_table can help the object  find the exact function  address.

 原文地址 http://www./career/?p=17465

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多