Article View: pl.comp.lang.c
Article #309190Re: Przykłady sprytnych wskaźników
From: Andyy
Date: Wed, 22 Feb 2017 19:34
Date: Wed, 22 Feb 2017 19:34
35 lines
1746 bytes
1746 bytes
W dniu 22.02.2017 o 19:25, Borneq pisze:
> Szukam krótkich kawałków kodów ilustrujących własności
> - unique_ptr
> - shared_ptr
> - weak_ptr
> Coś co można by sprawdzić przez stronę https://godbolt.org/
Działa std::move,
#include <memory>
int main()
{
std::unique_ptr<int[]> uptr1 = std::make_unique<int[]>(5);
std::unique_ptr<int[]> uptr2;
uptr2 = std::move(uptr1);
}
ale gdy zadeklaruję std::shared_ptr<int[]> sptr1;
to nie działają:
#include <memory>
int main()
{
std::unique_ptr<int[]> uptr1 = std::make_unique<int[]>(5);
std::shared_ptr<int[]> sptr1, sptr2;
sptr1 = std::move(uptr1);
}
#include <memory>
int main()
{
std::unique_ptr<int[]> uptr1 = std::make_unique<int[]>(5);
std::shared_ptr<int[]> sptr1, sptr2;
sptr1 = std::make_shared(uptr1);
}
Jako przekonwertować unique na shared + weak?
Technical Details
Message-ID:
<o8kp4a$tel$1@node1.news.atman.pl>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mailReferences:
<o8kl2g$p18$1@node1.news.atman.pl>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!.POSTED!not-for-mail From: Andyy <nie@spamowac.tego> Newsgroups: pl.comp.lang.c Subject: Re: Przykłady sprytnych wskaźników Date: Wed, 22 Feb 2017 20:34:33 +0100 Organization: ATMAN - ATM S.A. Lines: 35 Message-ID: <o8kp4a$tel$1@node1.news.atman.pl> References: <o8kl2g$p18$1@node1.news.atman.pl> NNTP-Posting-Host: 91.239.205.105 Mime-Version: 1.0 X-Trace: node1.news.atman.pl 1487792074 30165 91.239.205.105 (22 Feb 2017 19:34:34 GMT) X-Complaints-To: usenet@atman.pl NNTP-Posting-Date: Wed, 22 Feb 2017 19:34:34 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 In-Reply-To: <o8kl2g$p18$1@node1.news.atman.pl> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit