对autodesk公司面试题的完整解答

一部分自己完成,一部分别人完成
None.gif 一个类有基类、内部有一个其他类的成员对象,构造函数的执行顺序是怎样的。(Autodesk)
None.gif
None.gif
class  Abase
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
ExpandedSubBlockStart.gifContractedSubBlock.gif        Abase() 
dot.gif{ cout << "Abase construct" << endl; }
ExpandedBlockEnd.gif}
;
None.gif
None.gif
class  B
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
ExpandedSubBlockStart.gifContractedSubBlock.gif        B() 
dot.gif{ cout << "B construct" << endl; }
ExpandedBlockEnd.gif}
;
None.gif
None.gif
class  A
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
ExpandedSubBlockStart.gifContractedSubBlock.gif        A() 
dot.gif{ cout << "A construct" << endl; }
InBlock.gif    
InBlock.gif    
private:
InBlock.gif        B b;
ExpandedBlockEnd.gif}
;
None.gif
None.gifoutput:
None.gif    Abase construct    
None.gif    B construct
None.gif    A construct
None.gif
None.gif请描述一个你熟悉的设计模式(Autodesk)
None.gifbridge模式,将抽象的部分与它实现的部分分离,使它们可以独立的变化。
None.gifbridge模式一般使用在一个抽象部分对应多个不同的实现部分的时候。
None.gif例如:
None.gif
class  Shape 
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
InBlock.gif        
virtual Draw() = 0;
InBlock.gif    
private:
InBlock.gif        Draw 
*_dp;
InBlock.gif    
protected:
ExpandedSubBlockStart.gifContractedSubBlock.gif        Shap(Draw 
*dp) dot.gif{ _dp = dp; }
InBlock.gif        
void DrawLine(int x1, int y1, int x2, int y2);
InBlock.gif        
void DrawCircle(int x, int y, int r);
ExpandedBlockEnd.gif}
;
None.gif
None.gif
class  Rectrangle :  public  Shape
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
InBlock.gif        Draw();
InBlock.gif        Rectrangle(Draw
* dp, int x1, int y1, int x2, int y2);
InBlock.gif    
private:
InBlock.gif        
int _x1, _y1, _x2, _y2;
ExpandedBlockEnd.gif}
;
None.gif
None.gifRectrangle:Rectrangle(Draw
*  dp,  int  x1,  int  y1,  int  x2,  int  y2) : Shape(dp)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    _x1 
= x1, _y1 = y1, _x2 = x2, _y2 = y2;
ExpandedBlockEnd.gif}

None.gif
None.gifRectrangle:Draw()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    DrawLine(_x1, _y1, _x1, _y2);
InBlock.gif    DrawLine(_x1, _y2, _x2, _y2);
InBlock.gif    DrawLine(_x2, _y1, _x1, _y1);
InBlock.gif    DrawLine(_x1, _y1, _x2, _y2);
ExpandedBlockEnd.gif}

None.gif
None.gif
class  Cricle:  public  Shape
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
InBlock.gif        Draw();
InBlock.gif        Circle(Draw
* dp, int x, int y, int r);
InBlock.gif    
private:
InBlock.gif        
int _x, _y, _r;
ExpandedBlockEnd.gif}
;
None.gif
None.gif
None.gifCircle:Circle(Draw
*  dp,  int  x,  int  y,  int  r) : Shape(dp)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    _x 
= x, _y = y, _r = r;
ExpandedBlockEnd.gif}

None.gif
None.gifCircle:Draw()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    DrawCircle(_x, _y, _r);
ExpandedBlockEnd.gif}

None.gif
None.gif
None.gifClass Draw
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
InBlock.gif        
virtual void DrawLine(int x1, int y1, int x2, int y2) = 0;
InBlock.gif        
virtual void DrawCricle(int x, int y, int r) = 0;
ExpandedBlockEnd.gif}
;
None.gif
None.gifClass V1Draw : 
public  Draw
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
InBlock.gif        
void DrawLine(int x1, int y1, int x2, int y2);
InBlock.gif        
void DrawCricle(int x, int y, int r);    
ExpandedBlockEnd.gif}
;
None.gif
None.gifClass V2Draw : 
public  Draw
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public:
InBlock.gif        
void DrawLine(int x1, int y1, int x2, int y2);
InBlock.gif        
void DrawCricle(int x, int y, int r);    
ExpandedBlockEnd.gif}
;
None.gif
None.gif
None.gif
None.gif
None.gif在UML 中,聚合(aggregation)和组合(composition)有什么区别 (Autodesk)
None.gif聚合的特点是比较松的包含关系,如飞机场与飞机的关系,它是指一类事物的集聚关系。每个类都可以单独成为一个个体。
None.gif组合的特点是比较强的耦合关系,属于包容关系,比如A是由B,C组合,那么C是A的一部份。
None.gif
None.gifC#和C
++ 除了语法上的差别以外,有什么不同的地方?
None.gif
1 .c#不支持多重继承
None.gif
2 .c#在安全代码中不支持指针
None.gif
3 .c#具有自动垃圾回收机制
None.gif
None.gif
new  delete 与malloc free 的区别 ( Autodesk)
None.gif
1 .new是关键字,malloc是函数
None.gif
2 .new调用对象的构造函数, malloc只分配内存空间
None.gif
3 .new的内存分配算法与malloc的不同
None.gif
None.gif
None.gif
#define  DOUBLE(x) x+x (Autodesk)
None.gif
=   5 * DOUBLE( 10 ); i 是多少?正确的声明是什么?
None.gif
None.gif
=   5 * +  x =   5 * 10   +   10   =   60 ;
None.gif
#define  DOUBLE(x) ((x)+(x))
None.gif
None.gif有哪几种情况只能用intialization list 而不能用assignment
?
None.gif
1 .初始化基类的成员数据
None.gif
2 .初始化const,referance的成员对象。
None.gif
3 .类中包含的其他类对象,并且该对象需要参数构造。
None.gif
None.gifC
++ 是不是类型安全的? (Autodesk)
None.gif不是。
None.gif
None.gif描述内存分配方式以及它们的区别
None.gif
1 .静态内存区域,用于分配全局变量,静态变量和常量,编译期间
None.gif
2 .堆,用于动态分配内存,在调用malloc时,运行期间
None.gif
3 .栈,用于分配局部变量,编译期间
None.gif
None.gif比较一下C
++ 中static_cast 和 dynamic_cast 的区别
None.gif
1 .static_cast编译时进行类型转换检查, dynamic_cast在运行时进行类型转换
None.gif
2 .static_cast有点类似与c中的强制类型转换,dynamic_cast是沿着继承层次进行安全的类型转换,
None.gif
None.gifStruct 和class 的区别 (Autodesk)
None.gif
1 .作用域不同,struct的成员默认都是public; class中的成员默认为private
None.gif
2 .struct中不存在多态和虚拟继承。
None.gif
3 .class中的对象布局并不一定与声明次序一致。
None.gif
None.gif
None.gif当一个类A 中没有生命任何成员变量与成员函数,这时sizeof(A)的值是多少,如果不是零,请解释一下编译器为什么没有让它为零。(Autodesk)
None.gif
1 .等于1
None.gif
2 .为了在将来能实现对象的内存分配,编译器给空类提供了一个字节的占位符!
None.gif
None.gif
None.gif main 函数执行以前,还会执行什么代码? (Autodesk)
None.gif答案:全局对象的构造函数会在main 函数之前执行。
None.gif
None.gif
None.gif类成员函数的重载、覆盖和隐藏区别
None.gif答案:
None.gif成员函数被重载的特征:
None.gif
1 )相同的范围(在同一个类中);
None.gif
2 )函数名字相同;
None.gif
3 )参数不同;
None.gif
4 virtual  关键字可有可无。
None.gif覆盖是指派生类函数覆盖基类函数,特征是:
None.gif
1 )不同的范围(分别位于派生类与基类);
None.gif
2 )函数名字相同;
None.gif
3 )参数相同;
None.gif
4 )基类函数必须有virtual 关键字。
None.gif“隐藏”是指派生类的函数屏蔽了与其同名的基类函数,规则如下:
None.gif
1 )如果派生类的函数与基类的函数同名,但是参数不同。此时,不论有无virtual关键字,基类的函数将被隐藏(注意别与重载混淆)。
None.gif
2 )如果派生类的函数与基类的函数同名,并且参数也相同,但是基类函数没有virtual 关键字。此时,基类的函数被隐藏(注意别与覆盖混淆)
None.gif
None.gif(
2 )已知两个链表head1 和head2 各自有序,请把它们合并成一个链表依然有序,这次要求用递归方法进行。 ( Autodesk)
None.gif答案:
None.gifNode 
*  MergeRecursive(Node  * head1 , Node  * head2)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif   
if ( head1 == NULL )
InBlock.gif       
return head2 ;
InBlock.gif   
if ( head2 == NULL)
InBlock.gif       
return head1 ;
InBlock.gif   Node 
*head = NULL ;
InBlock.gif   
if ( head1->data < head2->data )
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif       head 
= head1 ;
InBlock.gif       head
->next = MergeRecursive(head1->next,head2);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif       head 
= head2 ;
InBlock.gif       head
->next = MergeRecursive(head1,head2->next);
ExpandedSubBlockEnd.gif   }

InBlock.gif   
return head ;
ExpandedBlockEnd.gif}

None.gif
None.gif
None.gif
15 .分析一下这段程序的输出 (Autodesk)
None.gif
class  B
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif
public:
InBlock.gif    B()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif       cout
<<"default constructor"<<endl;
ExpandedSubBlockEnd.gif    }

InBlock.gif    
~B()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif       cout
<<"destructed"<<endl;
ExpandedSubBlockEnd.gif    }

InBlock.gif    B(
int i):data(i)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif       cout
<<"constructed by parameter" << data <<endl;
ExpandedSubBlockEnd.gif    }

InBlock.gif
private:
InBlock.gif    
int data;
ExpandedBlockEnd.gif}
;
None.gifB Play( B b)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
return b ;
ExpandedBlockEnd.gif}

None.gif
int  main( int  argc,  char *  argv[])
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    B temp 
= Play(5);
InBlock.gif    
return 0;
ExpandedBlockEnd.gif}

None.gif请自己执行一下看看。
None.gif

转载于:https://www.cnblogs.com/moonz-wu/archive/2007/04/23/724479.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值