string "pveg - now. Btrangt"Cabbage Heads Hone*):
1.为对象分配内存:
2. 请用类构造函数,它
 ·为“Cabbnge Heads Hose 分配空间
 - # "Cabbage Heads Hoe"
 复制到分配的内存单元中
 - #f "Cabbage Heads Howe"
 的地址赋给str
 ·将值19粒给1en
 ·更新加理 strings(没有显示)
3.创建pveg变量
地址:2400
Catoage Heads Home\8
 地址:2000
 2000
19
地址:2400
4.将新对象的地址版给pveg变量:
pveg-地址:2800
2480
pveg-地址:2800
// compare object values
 // assign object address
图12.6 使用 new 创建对象
● 可以对对象指针应用解除引用操作符(*)来获得对象:
 if (sayings[i] < *first)
 first = &sayings[i]:
3. 再谈布局 new操作符
 本书前面介绍过,布局new操作符让您能够在分配内存时指定内存位置。第9章从内置类型的角度讨
 论了布局new操作符,将这种操作符用于对象时情况有些不同,程序清单12.8使用了布局new操作符和
 常规new 操作符给对象分配内存,其中定义的类的构造函数和析构函数都会显示一些信息,让用户能够了
 解对象的历史。
程序清单 12.8 placenew1.cpp
 // placenew1.cpp -- new, placement new, no delete
 #include <iostream>
 #include <string>
 #include <new>
 using namespace std;
 const int BUF = 512;
class JustTesting
private:
 string words;
 int number;
 public:
 JustTesting(const string & a = "Just Testing", int n = 0)
 (words = s; number = n; cout << words << " constructed\n"; }
 -JustTesting() | cout << words << " destroyed\n";}
 void Show() const { cout << words << ", " << number << endl; }
int main()
char * buffer w new char[BUF);
JustTesting *pcl, *pc2;
// get a block of memory