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]);
}
当分配给智能指针的内存带有new []时,我正在阅读有关delete和delete []的信息。为什么带有std::unique_ptr
的指令1没问题,而带有std::shared_ptr
的指令1没问题?
答案 0 :(得分:1)
GCC 7或更高版本将编译您遇到问题的代码:https://godbolt.org/z/pTWWVG
您在评论中链接的“ cpp.sh”网站使用了非常老的GCC 4.9,这是第一个声称支持C ++ 14的版本。