Ionut Alexandru
Ionut Alexandru

Reputation: 806

shared_ptr<int[]> doesn't compile

int main()
{
    //instruction 1 -> OK
    std::unique_ptr<int[]> sp2(new int[10]);

    //instruction 2 ->error does not compile
    std::shared_ptr<int[]> sp1(new int[10]);
}

I was reading about delete and delete[] when memory allocated for smart pointers is with new[]. Why instruction 1 with std::unique_ptr is ok and with std::shared_ptr isn't ?

Upvotes: 0

Views: 67

Answers (1)

John Zwinck
John Zwinck

Reputation: 249133

GCC 7 or later will compile the code you're having problems with: https://godbolt.org/z/pTWWVG

The "cpp.sh" website you linked in a comment uses GCC 4.9 which is pretty old, and was the first version that claimed to support C++14.

Upvotes: 1

Related Questions