#include <iostream> using namespace std; struct S { int a; S(int a) : a(a) { cout << "ctor " << a << " " << this << endl; } ~S() { cout << "dtor " << a << " " << this << endl; } }; S f() { S s (1); return S(2); } S g() { return S(3); } int main() { S&& r = f(); g(); S s (0); } % g++45 -std=gnu++0x rval.cc && ./a.out ctor 1 0x7fffffffe7e0 ctor 2 0x7fffffffe820 dtor 1 0x7fffffffe7e0 ctor 3 0x7fffffffe830 dtor 3 0x7fffffffe830 ctor 0 0x7fffffffe810 dtor 0 0x7fffffffe810 dtor 2 0x7fffffffe820 %右辺値参照のローカル変数で関数の戻り値を受けたら、寿命が延びるようだ。上の例で言うと、3はすぐに消えているが、2は最後まで残っている。
カテゴリ別アーカイブ
記事検索
最新記事
月別アーカイブ
アクセスカウンター
タグごと記事リンク
- 540
- AirCross
- android
- awk
- beer
- BitVisor
- blu-ray
- Bluetooth
- bunbougu
- C++
- chifure
- Cloud
- coloria
- cosme
- COVID19
- DC-GH6
- DIVE
- DMC-GH3
- DMC-GH4
- DMW-FL360L
- DSC-HX200V
- earsopen
- fisheye
- FreeBSD
- gcc
- Gfarm
- GH4
- Git
- GODOX
- GPU
- haskell
- HDD
- HG
- i288
- iijlab
- iijmio
- IPA
- IPv6
- jetglide
- KATA
- ke-non
- kernelvm
- Lowepro
- m43
- mercurial
- mesos
- Mew
- MNP
- mobilitas
- MOZA
- muji
- nail
- NAT
- nissin
- p2p
- pelikan
- Pen
- PH-1
- PLAN9
- platinum
- RX-8
- sandisk
- SCREEN
- SIRUI
- siwm
- skk
- sony
- SSD
- ssh
- stationery
- swex
- swim
- TASCAM
- tmux
- tokyo-olympic-2020
- topvalu
- TV
- ufs
- unix
- VAIO_type_P
- VM
- VoidTokyo
- whisky
- willcom
- WiMAX
- wine
- y!mobile
- ZFS
- zozo
- グラノーラ
- サングリア
- シェーバー
- ジェルネイル
- フルグラ
- ミューズリー
- 化粧品
- 品川区水泳大会
- 土佐文旦
- 常滑焼
- 靴
人気記事(週間)
人気記事(月間)