LoginSignup
1
2

More than 5 years have passed since last update.

C++ > unique_ptr > ポインタを取得する > .get() | EFFECTIVE C++ 68ページ目

Last updated at Posted at 2018-10-23
動作環境
C++ Builder XE4

.get()

unique_ptrで作成した後で、そのポインタを関数などで渡す時の書き方。

std::unique_ptr<TStringList> fileList(new TStringList);
getFileList(fileList.get()); // 使用例

getFileList()の中で特定フォルダのファイルリストをfileListに格納する、など。

Note: 過去のある時期によく実装していた内容だが、その後、別の作業(Python, numpy, NetCDF, NCLなど)をしているうちに書き方を忘れました。。。備忘録として記事にします。

参考

本(Kindle)の記載

@ EFFECTIVE C++: 55 Specific Ways to Improve Your Programs and Designs
by Scott Meyers
68ページ目(/279ページ)

tr1::shared_ptr and auto_ptr both offer a get member function to perform an explicit conversion, i.e., to return (a copy of)the raw pointer inside the smart pointer object:

int days = daysHeld(pInv.get()); // find, passes the raw pointer
                                 // in pInv to daysHeld
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2