定位new表达式

#include <iostream>
#include <new>

using namespace std;

const int chunk = 16;
class Foo{
public:
    int val() { return __val; }
    Foo() {
        __val = 0;
    }

private:
    int __val;
};

char *buf = new char[sizeof(Foo) * chunk];

int main(int argc, char* argv[])
{
    Foo *pb = new (buf)Foo;
    if (pb->val() == 0)
    {
        cout << "new expression worked!" << endl;
    }

    delete [] buf;
    return 0;
}
原文地址:https://www.cnblogs.com/licb/p/2663918.html