那位好心人帮帮忙,看看错那了
偶刚学这个
实在是没招了。。。。。。。
class fib_iterator
{
//friend class fib;
public:
friend int fib_iterator :: operator * ( const fib_iterator &rhs ) ;
fib_iterator( int index ) : _index ( index - 1 )
{}
bool operator == ( const fib_iterator &rhs ) const
{
return _index == rhs._index;
}
bool operator != ( const fib_iterator & rhs) const;
int operator * ( const fib_iterator & rhs ) const;
fib_iterator & operator ++() ;
fib_iterator operator ++( int );// postfix
private:
//void check_intergrity () const;
int _index;
};
class fib
{
friend class fib_iterator;
public:
//class fib_iterator;
friend int fib_iterator :: operator * ( const fib_iterator &rhs ) const;
fib( int len )
: _len( len>0?len:1 )
{
gr_ele();
}
fib()
: _len(1)
{
gr_ele();
}
int length() { return _fib.size(); }
bool gr_ele();
bool print_ele();
int ele( int index ) { return _fib[ index ] ; }
private:
//int fir_pos;
int _len ;
static vector< int > _fib;
};
inline bool
fib::gr_ele()
{
int inc;
if ( _len==1 || _len==2 )
for( inc=0; inc < _len; inc++)
_fib.push_back( 1 ) ;
else
{
_fib.push_back( 1 ) ;
_fib.push_back( 1 ) ;
for( inc = 2 ; inc < _len; inc++ )
_fib.push_back( _fib[ inc - 1 ] + _fib[ inc - 2 ] ) ;
}
return true;
}
inline bool
fib::print_ele()
{
int inc;
//gr_ele();
if ( _fib.size() <= 0)
return false;
for( inc = 0; inc < _len ; inc++)
cout<<_fib[inc]<<' ';
cout<<endl;
return true;
}
inline bool fib_iterator ::
operator != ( const fib_iterator &rhs ) const
{
return _index != rhs._index;
}
inline int fib_iterator ::
operator * ( const fib_iterator &rhs ) const
{
return fib :: _fib[ _index ] ;
}