How much is too much with C++11 auto keyword?

I’ve been using the new auto keyword available in the C++11 standard for complicated templated types which is what I believe it was designed for. But I’m also using it for things like: auto foo = std::make_shared<Foo>(); And more skeptically for: auto foo = bla(); // where bla() return a shared_ptr<Foo> I haven’t seen much … Read more

Why can I not push_back a unique_ptr into a vector?

What is wrong with this program? #include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>> vec; int x(1); std::unique_ptr<int> ptr2x(&x); vec.push_back(ptr2x); //This tiny command has a vicious error. return 0; } The error: In file included from c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/mingw32/bits/c++allocator.h:34:0, from c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/bits/allocator.h:48, from c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/memory:64, from main.cpp:6: c:\mingw\bin\../lib/gcc/mingw32/4.5.0/include/c++/bits/unique_ptr.h: In member function ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Tp*, const _Tp&) [with _Tp = std::unique_ptr<int>, … Read more