This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: std::shared_ptr compile error for 2D array type (G++7.2)


On 6 October 2017 at 11:48, Jonathan Wakely wrote:
> On 6 October 2017 at 09:47, goldenhawking wrote:
>> We use std::shared_ptr to hold 2D array like this:
>>
>> std::shared_ptr< int[24] > bar(new int[N][24], [=](int(*p)[24])->void {
>> delete[] p; } );
>>
>> GNU C++ 4/5/6 is ok . GNU C++ 7.2 gives an error message:
>>
>> error: no matching function for call to 'std::shared_ptr<int
>> [24]>::shared_ptr(int (*)[24])'  shared_ptr< int [24] > pt (new int
>> [4096][24]);
>>
>> This may be a problem caused by default construct mechanism of a 2D array.
>
> No, it's because in C++11 and C++14 shared_ptr was not designed to be
> used with arrays. In C++17 arrays are fully supported, but in a way
> that is incompatible with your code.
>
> It will work if you use shared_ptr<int[]24]> because that's actually a
> shared_ptr that owns a 2D array.

Oops, sorry for the type. I meant shared_ptr<int[][24]> not "int[]24]"
which isn't a valid type :-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]