vector模板的一点问题

qq_35875027 2017-11-15 05:03:58
自己练习写了个vec模板,有个函数一直出问题,哪里有问题啊
template <typename T>
class vec
{ ...
friend vec<T> operator+ <T>(const vec<T> &,const vec<T> &);
private:
iterator m_start;
iterator m_finished;
iterator m_limit;
allocator<T> alloc; //用作分配动态地址
};
template <typename T> vec<T> operator+(const vec<T> &v1,const vec<T> &v2)//两个vec连接起来
{
vec<T> v;
auto data=v.alloc.allocate(v1.size()+v2.size());
auto enu=uninitialized_copy(v1.begin(),v1.end(),data);
enu=uninitialized_copy(v2.begin(),v2.end(),enu);
v.m_start=data;
v.m_finished=v.m_limit=enu;
return v;
}
编译会有问题,坐等大佬
...全文
245 7 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
CT8100 2017-11-16
不是写的很明确么。。。 error: no type named ‘iterator_category’ in ‘struct std::iterator_
  • 打赏
  • 举报
回复
开源学开源 2017-11-16
不是去掉类里面头三点就可以编译成功了么?
  • 打赏
  • 举报
回复
baidu_37097818 2017-11-16
忘掉模板吧,对于很多人来说太复杂而且并非不可替代
  • 打赏
  • 举报
回复
qq_35875027 2017-11-15
引用 3 楼 hdt 的回复:
我想说的是,如果C++的语法还没有学习好,最好不要涉及模板
能告诉我哪里有问题吗大佬
  • 打赏
  • 举报
回复
我想说的是,如果C++的语法还没有学习好,最好不要涉及模板
  • 打赏
  • 举报
回复
qq_35875027 2017-11-15
g++ main.cpp -o main -std=c++11 In file included from /usr/include/c++/5/bits/stl_algobase.h:67:0, from /usr/include/c++/5/bits/char_traits.h:39, from /usr/include/c++/5/ios:40, from /usr/include/c++/5/ostream:38, from /usr/include/c++/5/iostream:39, from v.h:3, from main.cpp:1: /usr/include/c++/5/bits/stl_iterator.h: In instantiation of ‘class std::reverse_iterator<std::__cxx11::basic_string<char> >’: /usr/include/c++/5/bits/stl_iterator.h:334:5: required by substitution of ‘template<class _Iterator> std::reverse_iterator<_Iterator> std::operator+(typename std::reverse_iterator<_Iterator>::difference_type, const std::reverse_iterator<_Iterator>&) [with _Iterator = std::__cxx11::basic_string<char>]’ v.h:32:19: required from ‘class vec<std::__cxx11::basic_string<char> >’ main.cpp:4:18: required from here /usr/include/c++/5/bits/stl_iterator.h:97:11: error: no type named ‘iterator_category’ in ‘struct std::iterator_traits<std::__cxx11::basic_string<char> >’ class reverse_iterator ^ /usr/include/c++/5/bits/stl_iterator.h:111:55: error: no type named ‘difference_type’ in ‘struct std::iterator_traits<std::__cxx11::basic_string<char> >’ typedef typename __traits_type::difference_type difference_type; ^ /usr/include/c++/5/bits/stl_iterator.h:112:48: error: no type named ‘pointer’ in ‘struct std::iterator_traits<std::__cxx11::basic_string<char> >’ typedef typename __traits_type::pointer pointer; ^ /usr/include/c++/5/bits/stl_iterator.h:113:50: error: no type named ‘reference’ in ‘struct std::iterator_traits<std::__cxx11::basic_string<char> >’ typedef typename __traits_type::reference reference; ^ /usr/include/c++/5/bits/stl_iterator.h: In instantiation of ‘class std::move_iterator<std::__cxx11::basic_string<char> >’: /usr/include/c++/5/bits/stl_iterator.h:1152:5: required by substitution of ‘template<class _Iterator> std::move_iterator<_Iterator> std::operator+(typename std::move_iterator<_Iterator>::difference_type, const std::move_iterator<_Iterator>&) [with _Iterator = std::__cxx11::basic_string<char>]’ v.h:32:19: required from ‘class vec<std::__cxx11::basic_string<char> >’ main.cpp:4:18: required from here /usr/include/c++/5/bits/stl_iterator.h:965:50: error: no type named ‘reference’ in ‘struct std::iterator_traits<std::__cxx11::basic_string<char> >’ typedef typename __traits_type::reference __base_ref;
  • 打赏
  • 举报
回复
FoolCarpe 2017-11-15
报的啥错
  • 打赏
  • 举报
回复
发帖
C++ 语言

6.2w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2017-11-15 05:03
社区公告
暂无公告