12.5.3 再谈定位 new 运算符
本书前面介绍过,定位new运算符让您能够在分配内存时能够指定内存位置。第9章从内置类型的角度讨论了定位 new 运算符,将这种运算符用于对象时情况有些不同,程序清单12.8使用了定位 new 运算符和常规 new运算符给对象分配内存,其中定义的类的构造函数和析构函数都会显示一些信息,让用户能够了解对象的历史。
#pragma region 12.8 placenew1.cpp
//placenew1.cpp -- new placement new,no delete
#if 1
#include <iostream>
#include <string>
#include<new>
using namespace std;
const int BUF = 512;
class JustTesting
{
private:
string words;
int number;
public:
JustTesting(const string& s = "Just Testing", int n = 0)
{
words = s; number = n; cout << words <