在阅读C++ Primer Plus时,我几乎没有关于新位置的问题.
书中的示例代码如下:
class JustTesting{
private:
string words;
int number;
public:
JustTesting(const string & s = "Just Testing", int n = 0){
number = n;
words = s;
//some code here
}
~JustingTesting(){}
};
char * buffer = new char[BUF]; //get a block of memory
JustTesting *pc1, *pc2;
pc1 = new (buffer) JustTesting; //Place object in buffer
pc2 = new JustTesting("Heap1",20); //Place object on heap
//some code
JustTesting *pc3, *pc4;
pc3 = new (buffer) JustTesting("Bad Idea", 6);
pc4 = …Run Code Online (Sandbox Code Playgroud) 我在阅读C++ primer plus中的智能指针模板类时发现了这样的问题.这本书给出了一个如何实现auto_ptr类的例子,像这样,
template<class X> class auto_ptr {
public:
explicit auto_ptr(X* p = 0) throw();
...};
Run Code Online (Sandbox Code Playgroud)
构造函数结束时的throw()意味着此构造函数不会抛出异常.我知道这已被弃用,但我不知道为什么它需要禁用它的异常抛出.