c++ primer 第十九章习题
练习19.1 2
#include <iostream>
#include <cstdlib>
void *operator new(std::size_t n){
std::cout << "my new"<<endl;
if (void *mem = malloc(n))
return mem;
else
throw std::bad_alloc();
}
void operator delete(void *mem) noexcept{
std::cout << "my delete"<<endl;
free(mem);
}
int main()
{
using namespace std;
int *a = new int(486);
cout << a << " " << *a << endl;
delete a;
return 0;
}
练习19.3 (a T (b F 因为pb实际指向的对象是C的基类无法转换 (c T
练习19.4
try {
C& pc = dynamic_cast<C&>(*pa);
//
}
catch(bad_cast) {
}
练习19.5 当不能够使用虚函数完成又需要用基类指针或引用调用派生类成员的时候。
练习19.10 (a A* (b A& (c B&
练习19.11 区别在于指向数据成员的指针没有指定对象,调用符号不同,需要考虑访问权限。
练习19.12 const Screen::pos Screen::*pdata = &Screen::cursor;
练习19.13 const std: