- 相關(guān)推薦
2016年Adobe認(rèn)證面試題
Adobe 的客戶包括世界各地的企業(yè)、知識工作者、創(chuàng)意人士和設(shè)計者、OEM 合作伙伴,以及開發(fā)人員。下面一起來看看Adobe的認(rèn)證考試題庫,希望對大家有所幫助!
what is the rule of class D_*, UserCalss, and client class of D_* and UserClass to access the member of class B
class B{/*... ...*/};
class D_pri:private B{/*... ...*/};
class D_publ:public B{/*... ...*/};
class UserClass{ B b; /*... ...*/}
D_pri: 私有繼承自B,那么B中的public, private, protected在D_pri中修改為private,
“private繼承會將基類中的public和protected可見性的成員修改成為private可見性,這樣一來雖然派生類中同樣還是可以調(diào)用基類的protected和public成員,但是在派生類的派生類就不可以再調(diào)用被private繼承的基類的成員了。” from here
D_publ: 公有繼承自B,B中的三種類型在這個派生類中保持不變,派生類可以調(diào)用基類的protected和public成員,但是無法調(diào)用private成員
UserClass: 有一個B的對象b,b可以訪問b中的public成員函數(shù)及成員變量,但是無法訪問private和protected成員函數(shù)與變量
==========================我是問題分割線==========================
write the output:
[cpp] view plain copy print?
#include
#include
using namespace std;
void println(const string& msg)
{
cout<
}
class Base
{
public:
Base() { println("Base::Base()"); virt(); }
void f() { println("Base::f()"); virt(); }
virtual void virt() { println("Base::virt()"); }
};
class Derived :public Base
{
public:
Derived() { println("Derived::Derived()"); virt(); }
virtual void virt() { println("Derived::virt()"); }
};
void main()
{
Derived d;
cout<<"-------------------"<
Base *pB = &d;
pB->f();
}
output:
Base::Base()
Base::virt()
Derived::Derived()
Derived::virt()
-------------------
Base::f()
Derived::virt()
很少會在構(gòu)造函數(shù)和析構(gòu)函數(shù)中調(diào)用虛函數(shù),因為在它們中調(diào)用的虛函數(shù)將失去“多態(tài)”功能
==========================我是問題分割線==========================
static_cast 和 dynamic_cast有什么區(qū)別:
static_cast 沒有運(yùn)行時類型檢查來保證轉(zhuǎn)換的安全性;
dynamic_cast 用于類層次間(有繼承關(guān)系的)的向上或者向下類型轉(zhuǎn)換,也可以在兄弟類別中進(jìn)行轉(zhuǎn)換,它的安全性由RTTI來保證;
特別是當(dāng)處理向下類型轉(zhuǎn)換時用static_cast貌似成功轉(zhuǎn)換的結(jié)果也許會造成遭難, 若無法進(jìn)行向下類型轉(zhuǎn)換dynamic_cast會返回NULL.
參考:點擊打開鏈接
《Thinking in C++》
==========================我是問題分割線==========================
const char *p
char const *p;
前兩個的意思是一樣的,都是表示指向只讀(const)char型變量的指針,所以不能進(jìn)行 *p = 2; 這類修改被指對象值的操作
char * const p;
指針p是只讀的,指針的值不能修改,比如p++不可以。
const char const *p;
這個指針即指向只讀類型char的變量,本身又是只讀的
==========================我是問題分割線==========================
下面類的兩種構(gòu)造函數(shù)有什么區(qū)別
Sample::Sample(string name):_name(name){}
Sample::Sample(string name):{_name=name;}
----------------------------------------------我是回答分割線----------------------------------------------------
第一個調(diào)用了string的拷貝構(gòu)造,
第二個比較麻煩,先調(diào)用string的默認(rèn)構(gòu)造函數(shù),然后調(diào)用賦值操作符的重載函數(shù)
--------------------------------------------------測試代碼---------------------------------------------------------
[cpp] view plain copy print?
class A
{
int _counter;
public:
A() {cout<<"in A()"<
A(int i):_counter(i) {_counter= 0 ;cout<<"in A(int i)"<
A(const A &a) {_counter = a._counter; cout<<"A(const A &a)"<
A& operator = (const A &a)
{
if(this == &a )
return *this;
_counter = a._counter;
cout<<"in A& operator = (const A &a) "<
return *this;
}
};
class B
{
A _a;
public:
B(A &a)
{
_a = a;
}
};
void main()
{
A a(1);
cout<<"=============================="<
B b(a);
}
輸出結(jié)果:
in A()
in A& operator = (const A &a)
==========================我是問題分割線==========================
空類的系統(tǒng)自動產(chǎn)生的函數(shù)(至少寫四個)
默認(rèn)構(gòu)造函數(shù);
默認(rèn)拷貝構(gòu)造函數(shù);
默認(rèn)的operator = 函數(shù)
析構(gòu)函數(shù)
上述這幾個是確認(rèn)的,
還有一個取值函數(shù): const Empty* operator&() const; 這個我還不太確認(rèn)
==========================我是問題分割線==========================
怎樣防止類被繼承?對于不能被繼承的類,怎樣初始化及銷毀它的示例呢?
我的第一想法就是將構(gòu)造函數(shù)私有化,然后用靜態(tài)成員函數(shù)在堆上新建實例,
如果將析構(gòu)函數(shù)也私有化,那么需要一個靜態(tài)成員函數(shù)來做‘善后’工作
貌似這也符合提議,更加復(fù)雜的方法可見:猛點我
--------------------------------------------------測試代碼---------------------------------------------------------
[cpp] view plain copy print?
class uninheritable
{
int _value;
uninheritable(int v): _value(v){}
~uninheritable() {};
public:
static uninheritable *create(int v);
static void delete_uninherit(uninheritable* uninherit);
};
uninheritable* uninheritable::create(int v)
{
return new uninheritable(v);
}
void uninheritable::delete_uninhert(uninheritable* uninherit)
{
if( uninherit )
{
delete uninherit;
uninherit = NULL;
}
}
可以這么寫,編譯通過
class derived : public uninheritable
{
// add what you want the class to do
};
但是,如果你想初始化derived類的一個對象,那么編譯器報錯,因為基類的構(gòu)造函數(shù)是私有的,派生類的構(gòu)造函數(shù)無法調(diào)用基類的私有成員函數(shù)
==========================我是問題分割線==========================
產(chǎn)生繼承類實例時構(gòu)造函數(shù)的調(diào)用次序(基類包含虛函數(shù),繼承類重寫了)
基類構(gòu)造函數(shù)先被調(diào)用,然后再調(diào)用派生類的構(gòu)造函數(shù),而且基類構(gòu)造函數(shù)在派生類構(gòu)造函數(shù)的初始化列表中被調(diào)用,
如果有繼承自多個基類,那么按照public A,B,C的依次順序,而不是在初始化列表中的順序。
貌似這題很簡單啊,但是為什么強(qiáng)調(diào)“基類包含虛函數(shù),繼承類重寫了”
想來想去只有虛函數(shù)表指針的初始化問題,所以應(yīng)該是這樣:
設(shè)置基類vptr, 然后執(zhí)行基類構(gòu)造函數(shù)的初始化列表,執(zhí)行基類構(gòu)造函數(shù)體,
再進(jìn)行派生類初始化列表中其他初始化(比如先進(jìn)行成員對象,再內(nèi)建類型初始化,假設(shè)有),然后派生類的vptr初始化,然后進(jìn)入派生類構(gòu)造函數(shù)體。
還要再查權(quán)威的C++書。
==========================我是問題分割線==========================
手工實現(xiàn) strcpy 函數(shù),不能使用任何庫函數(shù),要求處理 NULL、溢出等異常:
可能以下函數(shù)沒有完全符合題意,模仿了strncpy這個函數(shù)
[cpp] view plain copy print?
/*
Description: Copies the first num characters of source to destination
dst:
Pointer to the destination array where the content is to be copied.
src
string to be copied.
num
Maximum number of characters to be copied from source.
*/
char* mystrncpy(char *dst, const char *src, size_t num)
{
if( NULL == dst )
return NULL;
if( NULL == src )
return dst;
const char *pSrc = src;
char *pDst = dst;
int max_num = num;
while( *pSrc != '\0' && --max_num >= 0 )
{
*pDst++ = *pSrc++;
}
for( int i=0; i
*pDst++ = 0;
return dst;
}
==========================我是問題分割線==========================
對于給定的一個數(shù)字,將其對應(yīng)的二進(jìn)制的最右邊的1改為0("turn off"),例如給你14, 二進(jìn)制位1110, 函數(shù)處理后為1100,對應(yīng)為12,寫出實現(xiàn)這個功能的函數(shù)
[cpp] view plain copy print?
#include
#include
using namespace std;
void Turnoff(int &number)
{
int int_len = sizeof(int);
int mask = 1;
for( int i=0; i
{
if( (mask & number) > 0 )
{
number = number - mask;
break;
}
mask = mask << 1;
}
}
void main()
{
int number=1240;
bitset <32> myset(number);
cout<<"before turning off:"<
Turnoff(number);
myset = number;
cout<<"after turning off: "<
}
【Adobe認(rèn)證面試題】相關(guān)文章:
Adobe認(rèn)證ning認(rèn)證簡介09-20
adobe photoshop 認(rèn)證試題08-29
Adobe ACCD認(rèn)證介紹09-28
Adobe認(rèn)證Illustrator試題及答案07-08
Adobe面試題及答案08-27
Adobe InDesign認(rèn)證試題及答案04-03
Adobe認(rèn)證Photoshop考試試題07-03
Adobe認(rèn)證考試常見問題07-27