由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - return Triangular_iterator( _beg_pos );意思
相关主题
一个C++的概念问题C++ template function一个问题
呼唤大侠们,我实在不能实现C++泛型的精神。c++ template question:
为什么在overloading中,friend <<不能读取private值呢?overriding operator<<
请问这是什么错误呀问个C++的问题 friend operator
Why should i include .cpp instead of .hc++小问题
C++ template questioniterator一问
请问关于overloading <<partial_sort问题
再问两个C++问题please help debug this code
相关话题的讨论汇总
话题: triangular话题: iterator话题: int话题: beg话题: pos
进入Programming版参与讨论
1 (共1页)
k*******3
发帖数: 1909
1
下面程序copy来自C++ essential 4.7节,
Triangular_iterator begin() const
{ return Triangular_iterator( _beg_pos ); }
请问
return Triangular_iterator( _beg_pos ); 这句话的语法是怎么样的?
Triangular_iterator是自定义的一个class吧,class后面直接加(_beg_pos)什么意思
呢?
如果是返回一个Triangular_iterator的object, 不需要定义成
Triangular_iterator obj(_beg_pos);
return obj;吗?
谢谢!
================================Full Class definition==================
class Triangular_iterator
{
public:
Triangular_iterator( int index ) : _index( index-1 ){} //***
// other member functions
private:
void check_integrity() const;
int _index;
};
class Triangular {
friend class Triangular_iterator;
public:
Triangular( int len = 1, int bp = 1 );
Triangular( const Triangular& );
Triangular& operator=( const Triangular &rhs );
int length() const { return _length; }
int beg_pos() const { return _beg_pos; }
int elem( int pos ) const;
void length( int nlen ) { _length = nlen; }
void beg_pos( int npos ){ _beg_pos = npos; }
bool next( int &val ) const;
void next_reset() const { _next = 1; }
static bool is_elem( int );
static void gen_elements( int length );
static void gen_elems_to_value( int value );
static void display( int length, int beg_pos, ostream &os = cout );
typedef Triangular_iterator iterator;
Triangular_iterator begin() const
{ return Triangular_iterator( _beg_pos ); }
Triangular_iterator end() const
{ return Triangular_iterator( _beg_pos+_length ); }
private:
int _length; // number of elements
int _beg_pos; // beginning position of range
mutable int _next; // next element to iterate over
// static const int _max_elems = 1024; // ok, but not VC++
enum { _max_elems = 1024 };
static vector _elems;
};
f*******n
发帖数: 12623
2
return Triangular_iterator( _beg_pos );

Triangular_iterator obj(_beg_pos);
return obj;
一样效果
k*******3
发帖数: 1909
3
thanks

【在 f*******n 的大作中提到】
: return Triangular_iterator( _beg_pos );
: 和
: Triangular_iterator obj(_beg_pos);
: return obj;
: 一样效果

1 (共1页)
进入Programming版参与讨论
相关主题
please help debug this codeWhy should i include .cpp instead of .h
C++中怎么传递std::hex这样的参数啊C++ template question
子类的assignment operator 怎么访问父类的private member请问关于overloading <<
C++ template question with friend ostream再问两个C++问题
一个C++的概念问题C++ template function一个问题
呼唤大侠们,我实在不能实现C++泛型的精神。c++ template question:
为什么在overloading中,friend <<不能读取private值呢?overriding operator<<
请问这是什么错误呀问个C++的问题 friend operator
相关话题的讨论汇总
话题: triangular话题: iterator话题: int话题: beg话题: pos