g++编译时出现如下问题,各位高手帮忙一下

dandanzhang 2009-03-19 09:16:39
编译时的错误如下:
In member function 'typename MxBlock<T>::const_iterator MxDynBlock<T>::end() const':
MxDynBlock.h:66 there are no argument to begin that depend on a template parameter ,so a declaration of begin must be available!!!
代码如下:

template<class T>
class MxDynBlock : public MxBlock<T>
{
private:
int fill;

public:
MxDynBlock(int n=2) : MxBlock<T>(n) { fill=0; }

int length() const { return fill; }
int total_space() const { return MxBlock<T>::length(); }

int last_id() const { return fill-1; }
T& last() { return (*this)[last_id()]; }
const T& last() const { return (*this)[last_id()]; }

void room_for(int len)
{
if( length()<len ) resize(len);
fill = len;
}

T& add()
{
if( length()==total_space() ) resize(total_space() * 2);
fill++;
return last();
}

void add(const T& t) { add() = t; }

void reset() { fill = 0; }
T& drop() { return (*this)[--fill]; }
void drop(int d) { fill -= d; }

void remove(int i) { (*this)[i] = (*this)[--fill]; }
void remove_inorder(int i)
{ memmove(&(*this)[i], &(*this)[i+1], (--fill - i)*sizeof(T)); }

// Restricted STL-like interface for interoperability with
// STL-based code. Overrides select MxBlock<> definitions and
// introduces some additional std::vector-like methods.
//
int size() const { return length(); }

typename MxBlock<T>::iterator end() { return begin()+size(); }
typename MxBlock<T>::const_iterator end() const { return begin()+size(); }

void push_back(const T& t) { add(t); }
};

template<class T, int T_SIZE>
class MxSizedDynBlock : public MxDynBlock<T>
{
public: MxSizedDynBlock(uint n=T_SIZE) : MxDynBlock<T>(n) { }
};

template<class T>
inline bool varray_find(const MxDynBlock<T>& A, const T& t, uint *index=NULL)
{
for(unsigned int i=0; i<A.length(); i++)
if( A[i] == t )
{
if( index ) *index = i;
return true;
}
return false;
}

// MXDYNBLOCK_INCLUDED
#endif
#include "MxBlock.h"

template<class T>
class MxDynBlock : public MxBlock<T>
{
private:
int fill;

public:
MxDynBlock(int n=2) : MxBlock<T>(n) { fill=0; }

int length() const { return fill; }
int total_space() const { return MxBlock<T>::length(); }

int last_id() const { return fill-1; }
T& last() { return (*this)[last_id()]; }
const T& last() const { return (*this)[last_id()]; }

void room_for(int len)
{
if( length()<len ) resize(len);
fill = len;
}

T& add()
{
if( length()==total_space() ) resize(total_space() * 2);
fill++;
return last();
}

void add(const T& t) { add() = t; }

void reset() { fill = 0; }
T& drop() { return (*this)[--fill]; }
void drop(int d) { fill -= d; }

void remove(int i) { (*this)[i] = (*this)[--fill]; }
void remove_inorder(int i)
{ memmove(&(*this)[i], &(*this)[i+1], (--fill - i)*sizeof(T)); }

// Restricted STL-like interface for interoperability with
// STL-based code. Overrides select MxBlock<> definitions and
// introduces some additional std::vector-like methods.
//
int size() const { return length(); }

typename MxBlock<T>::iterator end() { return begin()+size(); }
typename MxBlock<T>::const_iterator end() const { return begin()+size(); }

void push_back(const T& t) { add(t); }
};

template<class T, int T_SIZE>
class MxSizedDynBlock : public MxDynBlock<T>
{
public: MxSizedDynBlock(uint n=T_SIZE) : MxDynBlock<T>(n) { }
};

template<class T>
inline bool varray_find(const MxDynBlock<T>& A, const T& t, uint *index=NULL)
{
for(unsigned int i=0; i<A.length(); i++)
if( A[i] == t )
{
if( index ) *index = i;
return true;
}
return false;
}

// MXDYNBLOCK_INCLUDED
#endif
多谢各位
...全文
97 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xianyuxiaoqiang 2009-03-20
  • 打赏
  • 举报
回复
自己查查看
Cpp权哥 2009-03-19
  • 打赏
  • 举报
回复
你的代码前面一大段都贴重复了,
而且没有模板MxBlock的代码,无法查错。
sagegz 2009-03-19
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 zmlovelx 的回复:]
要是以前空闲的我,应该会马上 copy代码 然后查错抢分
可惜现在不刷分了
其实没有动手解决不了的问题
[/Quote]
的确是这样,师兄很忙了~!
帅得不敢出门 2009-03-19
  • 打赏
  • 举报
回复
要是以前空闲的我,应该会马上 copy代码 然后查错抢分
可惜现在不刷分了
其实没有动手解决不了的问题
xuruichen 2009-03-19
  • 打赏
  • 举报
回复
代码太多了,标出来好看啊!!
  • 打赏
  • 举报
回复
楼主,你至少把出问题的点标出来吧。
fairchild811 2009-03-19
  • 打赏
  • 举报
回复
begin()和end()的代码呢,他们必须是const型的函数才能被const的函数调用

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧