【初心者歓迎】C/C++室 Ver.55【環境依存OK】at TECH
【初心者歓迎】C/C++室 Ver.55【環境依存OK】 - 暇つぶし2ch105:デフォルトの名無しさん
08/06/17 21:25:32
>>102
何をしたいのか理解に苦しむけど、リファレンス返すのはどう?
#include <iostream>
#include <memory>
class NoCopy {
  int val_;
  NoCopy(const NoCopy&);
  NoCopy& operator=(const NoCopy&);
public:
  NoCopy(int val) : val_(val) {}
  void dump() const { std::cerr << val_ << std::endl; }
};
class Hoge {
  std::auto_ptr<NoCopy> nocopy_;
public:
  Hoge() : nocopy_(0) {}
  operator NoCopy&() {
    nocopy_ = std::auto_ptr<NoCopy>(new NoCopy(1));
    return *nocopy_.get();
  }
};
int main() {
  Hoge h;
  NoCopy& nocopy = h;
  nocopy.dump();
}


次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch