1.寫(xiě)出下面程序的輸出
class abc;
void del(abc *pobj){
delete pobj;
}
class abc{
public:
abc(){
printf("abc\r\n");
}
~abc(){
printf("~abc\r\n");
}
};
int main()
{
abc *pobj = new abc;
del(pobj);
}
2.寫(xiě)出下面程序的輸出
void* operator new(size_t size)
{
printf("malloc %u\r\n", size);
return malloc(size);
}
void operator delete(void *memblock){
printf("free\r\n");
return free(memblock);
}
class abc{
public:
abc(){
printf("abc\r\n");
throw int();
}
~abc(){
printf("~abc\r\n");
}
};
int main(){
try{
new abc;
}catch(int& i){
printf("%d\r\n", i);
}
return 0;
}
3.寫(xiě)出下面程序的輸出
template <typename T>
class abc{
public:
abc(){
printf("primary\r\n");
}
};
template<>
abc<int>::abc(){
printf("member spec\r\n");
};
template<typename T, typename P>
class abc<T (*)(P)>{
public:
abc(){
printf("partial spec\r\n");
}
};
int main()
{
abc<void* (*)(int)> f_abc;
abc<int> i_abc;
}
4.下面的代碼能否通過(guò)編譯?為什么
class a{
public:
virtual ~a(){
}
private:
void operator delete(void *p);
};
int main()
{
a _1;
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。