'I try to use placement new, but always complies error

    #include <iostream>
    #include <new>
    
    const int BUF = 512;
    const int N = 5;
    char buffer[BUF];

    int main(){
        using namespace std;
    

        double *pd1, *pd2;
        int i;
        cout << "Calling new and placement new: \n";
        pd1 = new double[N];
        pd2 = new (buffer) double[N];
        for(i = 0; i < N; i++){
            pd2[i] = pd1[i] = 1000 + 20.0 * i;
        }
        cout << "Memory addresses:\n" << " heap: " << pd1
            << " static: " << (void *)buffer << endl;
        cout << "Memory contents:\n";
        for(i = 0; i < N; i++){
            cout << pd1[i] << " at " << &pd1[i] << "; ";
            cout << pd2[i] << " at " << &pd2[i] << endl;
        }
        delete [] pd1;
        return 0;
}

newplace.cpp:15:32: error: no matching function for call to ‘operator new [](sizetype, char [512])’ pd2 = new (buffer) double[N];



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source