⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intvec.hh

📁 C++作业
💻 HH
字号:
# ifndef IntVec_hh# define IntVec_hh IntVec_hhusing namespace std;# include <iostream>class IntVec {public:    //*******************************************************************************    // Nested Classes    //  This is an example of many things:    //    - how C++ defines nested classes    //    - default arguments in C++ (see the constructor definition)    //    - the importance of understanding what scope you are in    //      when defining classes and methods.    //    - how C++ allows operators to be overloaded.    //    - how to iterator the Iterator pattern for C++ vectors.    //    //  IMPORTANT: You will need to add behavior to this nested class    //  in order to get IntVec working properly. You are free to    //  change anything you want in this class, and to add any    //  additional functionality    class iterator {      public:	iterator(IntVec* container = NULL, int position = 0);	iterator(iterator& it);	inline const IntVec* getContainer() const { return this->_container; }	inline int getPosition() const { return this->_position; }	// This will allow us to increment an iterator (whose semantics	// is to advance the position	iterator& operator++();	// This allows us to "dereference" an iterator instance to obtain	// the element of the underlying container that the iterator	// is currently refering to.	//	// IMPORTANT: Determine whether we really should be using	// 'int&' as the return type (and if not, change it as appropriate).	// To determine this, find out whether the real vector<int>::iterator	// has a reference return type for operator* (by writing code	// to experiment with whether you can use '*it' on the left-hand	// side of an assignment).	int& operator*();	// This allows us to compare two iterators.  Returns true	// if they are NOT equal, false if they ARE equal.	bool operator!=(const iterator& it) const;      protected:	inline void setContainer(IntVec* vec) { this->_container = vec; }	inline IntVec*& container() { return this->_container; } 	inline void setPosition(int pos) { this->_position = pos; }	inline int& position() { return this->_position; }      private:        IntVec* _container;	// This is 'int' instead of 'unsigned int' because we use	// -1 to mean something special (end)	int _position;    };    // NOTE: It is important to define the nested 'iterator' class BEFORE    // we use it so that the compiler knows it exists.    //*******************************************************************************    // Constructors/Destructors    IntVec();    // Accessors    // Input/Output    // Miscellaneous    static void test();protected:    // Accessors    // Methods  private:     // Accessors    // Methods     // State};# endif // IntVec_hh

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -