c++ - GCC shared_ptr Template Error -
the following function
#include <memory> template<typename t> std::shared_ptr<typename t> tail(const std::shared_ptr<typename t>& cont, size_t n) { const auto size(std::min<size_t>(n, cont->size())); return std::shared_ptr<typename t>(new t(cont->end() - size, cont->end())); }
produces following error on gcc 4.7.2.
g++ test.cpp -std=c++0x test.cpp:4:27: error: template argument 1 invalid test.cpp:4:66: error: template argument 1 invalid test.cpp: in function ‘int tail(const int&, size_t)’: test.cpp:6:42: error: base operand of ‘->’ not pointer test.cpp:7:35: error: template argument 1 invalid test.cpp:7:47: error: base operand of ‘->’ not pointer test.cpp:7:67: error: base operand of ‘->’ not pointer
i understand cont not 'look' pointer, compiles fine on vs2012. how can write function gcc?
just remove typename
s
template<typename t> std::shared_ptr<t> tail(const std::shared_ptr< t>& cont, size_t n) { const auto size(std::min<size_t>(n, cont->size())); return std::shared_ptr< t>(new t(cont->end() - size, cont->end())); }
Comments
Post a Comment