由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - a c++ question
相关主题
请教一下这个template function在gcc下要怎么修改C++ 菜鸟问一个关于template 的问题。
template 疑问文一个简单的c++
C++ template questionc++ iterator 弱问
问个c++的template的问题请问这是什么错误呀
谁给详细说一下这句How does template work in C++
一个C++ template的问题这段 C++ 怎么改才能编译?
[菜鸟问题]类模板问题C++ linking 弱问 (one file)
c++ template question:C++ template question
相关话题的讨论汇总
话题: const话题: iterator话题: int话题: set话题: myiter
进入Programming版参与讨论
1 (共1页)
p******g
发帖数: 347
1
Since std::set::iterator only support ++ and --, i write a piece of code to do
the + (and -) functionality.
the code is below:
set::const_iterator& operator+(set::const_iterator& it, const int& n
)
{
for (int i=0; i return it;
}
it works fine. But only for set. I want to write a generic function, the
code is
template
set::const_iterator& operator+(set::const_iterator& it, const int& n)
{
for (int i=0; i return it;
}
Even more gene
t*q
发帖数: 104
2
why not use the built-in "advance" function?

do
n
the

【在 p******g 的大作中提到】
: Since std::set::iterator only support ++ and --, i write a piece of code to do
: the + (and -) functionality.
: the code is below:
: set::const_iterator& operator+(set::const_iterator& it, const int& n
: )
: {
: for (int i=0; i: return it;
: }
: it works fine. But only for set. I want to write a generic function, the

p******g
发帖数: 347
3
yeah right, surely you can use it but what if there is no advance?
hehe just for the sake of pedagogy, how to solve the problem?
I come up with an ugly solution
template
struct MyIter : T::iterator {
MyIter(const T& a) : T::iterator(a.begin()) {};
MyIter& operator+(const int& n);
};
template
MyIter& MyIter::operator+(const int& n)
{
for (int i=0; i return *this;
}
Any better idea? it seems I can't use "T::iterator &" why?

【在 t*q 的大作中提到】
: why not use the built-in "advance" function?
:
: do
: n
: the

p***o
发帖数: 1252
4
you need 'typename', i.e,
typename std::set::const_iterator &it

do
n
the

【在 p******g 的大作中提到】
: Since std::set::iterator only support ++ and --, i write a piece of code to do
: the + (and -) functionality.
: the code is below:
: set::const_iterator& operator+(set::const_iterator& it, const int& n
: )
: {
: for (int i=0; i: return it;
: }
: it works fine. But only for set. I want to write a generic function, the

p******g
发帖数: 347
5
cool.
thanks that resolved the problem.

【在 p***o 的大作中提到】
: you need 'typename', i.e,
: typename std::set::const_iterator &it
:
: do
: n
: the

1 (共1页)
进入Programming版参与讨论
相关主题
C++ template question谁给详细说一下这句
Cannot use my own container as the underlying container of a stack? (c++)一个C++ template的问题
一个关于C++ template和overload的问题[菜鸟问题]类模板问题
C++ templatec++ template question:
请教一下这个template function在gcc下要怎么修改C++ 菜鸟问一个关于template 的问题。
template 疑问文一个简单的c++
C++ template questionc++ iterator 弱问
问个c++的template的问题请问这是什么错误呀
相关话题的讨论汇总
话题: const话题: iterator话题: int话题: set话题: myiter