VisualC  tr1中的shared_ptr和随机数计算机等级考试
文章作者 100test 发表时间 2010:01:08 18:38:45
来源 100Test.Com百考试题网
 
    
  前面说了tr1全身都是宝,最近在重构中,刚好用到了其中的shared_ptr,也就是我们常说的智能指针Smart Pointer。关于智能指针,其实是C  程序员的一个梦想。我们都知道,在C#中,我们只需要new,而不需要0delete,这成为多少C  程序员眼馋的特性。今天通过tr1中的shared_ptr也基本上实现这种主动申请,自动释放的内存管理突然醒,解救C  程序员与内存管理的水深火热之中。说了这么多,我们来看一个shared_ptr和随机数种和应用的例子。
  #include "stdafx.h"
  #include "time.h" // 作为随机数引擎种子的需要
  #include "functional"
  #include "vector"
  #include "algorithm"
  #include "random" // 随机数的头文件
  #include "iostream"
  //#include "shared_ptr"
  using namespace std.
  using namespace std::tr1.
  class Demo
  {
  public:
  Demo(double fVal)
  {
  m_fVal = fVal.
  }
  public:
  bool greater(double fVal)
  {
  // do something
  return fVal