[ create a new paste ] login | about

Link: http://codepad.org/rEYQ6YiK    [ raw code | fork ]

ninwa - C++, pasted on Feb 16:
#include <vector>
#include <memory>

class Foo 
{
public:
  int m_X;
  Foo(int x) : m_X(x) {} 
};

template <typename T>
std::vector< tr1::shared_ptr<T> > nCopies(const T& source, int n)
{
  std::vector< tr1::shared_ptr<T> > copies;
  while(n-- > 0)
  {
      tr1::shared_ptr<T> a(new T(source));
      copies.push_back(a);
  }

  return copies;
}

int main()
{
    Foo f1(10);
    std::vector< tr1::shared_ptr<Foo> > copies = nCopies<Foo>(f1, 2);
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: