1.写出下面程序的输出
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.写出下面程序的输出
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.写出下面程序的输出
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.下面的代码能否通过编译?为什么
class a{
public:
virtual ~a(){
}
private:
void operator delete(void *p);
};
int main()
{
a _1;
}
c/c++面试题(3)
最新推荐文章于 2023-12-18 18:51:46 发布