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

📄 intvec.cc

📁 C++作业
💻 CC
字号:
# include <iostream># include "IntVec.hh"  // ******************************************************************// CONSTRUCTORSIntVec::IntVec() {    // Default Constructor}// ******************************************************************// ACCESSORS// ******************************************************************// METHODSvoid IntVec::test() {    cerr << "NOTE: Testing IntVec" << endl;}// ******************************************************************// CODE FOR NESTED CLASS 'iterator'// ******************************************************************IntVec::iterator::iterator(IntVec* vec, int position) {    // NOTE: The header file provides default arguments    // for both 'vec' (NULL) and 'position' (0).  However,    // when defining the method, you do NOT provide the    // default values).    this->setContainer(vec);    this->setPosition(position);}IntVec::iterator::iterator(IntVec::iterator& it) {    // Why aren't we passing 'it' as a 'const iterator&' here?    // Can you find a way to solve this problem?    this->setContainer( it.container() );    this->setPosition( it.getPosition() );}IntVec::iterator& IntVec::iterator::operator++() {    // We increment our current position by one.    // If the result is beyond the range of the    // underlying vector (or if the position is already    // marking the "end"), we set the position to    // the special value -1.    // Uncomment this when you get 'size' working on IntVec    /*    int pos = this->getPosition();    if ( pos >= 0 ) {	++pos;	unsigned sz  = this->getContainer()->size();	if ( ((unsigned)pos) < sz ) {	    this->setPosition(pos);	} else {	    this->setPosition(-1);	}    }    */    return *this;}int& IntVec::iterator::operator*() {    // FIX THIS CODE!  This is NOT safe code.  Why it is    // unsafe is left as an exercise.    #ifdef WORKING    // Remove the 'ifdef' when you get operator[] working in IntVec    // (or use some other method to gain access to an element    // of the IntVec container    IntVec* container = this->container();    return (*container)[this->getPosition()];    # else    // This is just a temporary hack until you get the preceeding code working.    // You should determine why I am doing this.  Why have any code    // here at all?  Why use a static variable?  Remember that this    // is just a hack, it isn't actually doing what it is supposed to.    static int i = 0;    return i;    # endif // not WORKING}bool IntVec::iterator::operator!=(const iterator& it) const {    return ((this->getPosition() == it.getPosition()) &&	    (this->getContainer() == it.getContainer())) ? false : true;}

⌨️ 快捷键说明

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