筆試題(程序的輸出)
分析一下這段程序的`輸出 (Autodesk)
class B
{
public:
B()
{
cout<<"default constructor"<<endl;
}
~B()
{
cout<<"destructed"<<endl;
}
B(int i):data(i) //B(int) works as a converter ( int -> instance of B)
{
cout<<"constructed by parameter " << data <<endl;
}
private:
int data;
};
B Play( B b)
{
return b ;
}
(1) results:
int main(int argc, char* argv[]) constructed by parameter 5
{ destructed B(5)形參析構(gòu)
B t1 = Play(5); B t2 = Play(t1); destructed t1形參析構(gòu)
return 0; destructed t2 注意順序!
} destructed t1
(2) results:
int main(int argc, char* argv[]) constructed by parameter 5
{ destructed B(5)形參析構(gòu)
B t1 = Play(5); B t2 = Play(10); constructed by parameter 10
return 0; destructed B(10)形參析構(gòu)
} destructed t2 注意順序!
destructed t1
【筆試題(程序的輸出)】相關(guān)文章:
360筆試題目10-20
華為2017筆試題08-16
華為2017筆試試題08-10
桂林銀行筆試題筆經(jīng)10-21
華為系統(tǒng)程序招聘筆試題10-23
阿里巴巴程序筆試題01-16
普通PHP程序員筆試題11-25
java程序員面試題08-27
java程序員面試試題08-14
輸出解像度10-08