From: Jonathan Wakely <jwakely.gcc@gmail.com>
To: goldenhawking <goldenhawking@163.com>
Cc: libstdc++@gcc.gnu.org
Subject: Re: std::shared_ptr compile error for 2D array type (G++7.2)
Date: Fri, 06 Oct 2017 10:48:00 -0000 [thread overview]
Message-ID: <CAH6eHdQQP1cX-T-_zbqEQwKQyBYc_RWygC6snPnrXrW3QXb1dw@mail.gmail.com> (raw)
In-Reply-To: <8b4734be-720b-6ce3-74b7-d179fb53a800@163.com>
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.
next prev parent reply other threads:[~2017-10-06 10:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-06 8:47 goldenhawking
2017-10-06 10:48 ` Jonathan Wakely [this message]
2017-10-06 11:02 ` Jonathan Wakely
2017-10-06 11:25 ` Jonathan Wakely
[not found] <59d76db6.4cb4630a.96427.f76cSMTPIN_ADDED_BROKEN@mx.google.com>
[not found] ` <CAH6eHdTSAaDM0m9eOWnO84q9wxRWqh_84=0ZMPe6Lqvgj_No+g@mail.gmail.com>
2017-10-06 13:27 ` std^shared_ptr " goldenhawking
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAH6eHdQQP1cX-T-_zbqEQwKQyBYc_RWygC6snPnrXrW3QXb1dw@mail.gmail.com \
--to=jwakely.gcc@gmail.com \
--cc=goldenhawking@163.com \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).