But you can access vectors w/o using iterators. In some instances , such as removing items from a vector, you must use an iterator. Most others you can access them like an array.
Code:
class FooMgr;
class Foo
{
friend class FooMgr;
protected:
int m_iSize;
unsigned int *m_pArray;
private:
Foo():m_iSize(0),m_pArray(NULL) { }
Foo(const Foo &);
Foo &operator =(const Foo &);
void Destroy(void)
{
//For msvc 6 - '03,'05 do not suffer from this issue
if (m_pArray)
{
delete [] m_pArray;
m_pArray=NULL;
}
}
bool Create(int iSize)
{
m_pArray=new int[iSize];
if (!m_pArray)
{
return true;
} else return false;
}
bool GetValue(int iOffset,int &ioutValue)
{
if (iOffset>m_iSize) return true;
iOutValue=m_pArray[iOffset];
return false;
}
bool SetValue(int iOffset,int iValue)
{
if (iOffset>m_iSize) return true;
m_pArray[iOffset=iValue;
return false;
}
unsigned int GetSizeOfArray() {return m_iSize;}
};
class FooMgr
{
private:
std::vector<Foo *> FooVector;
FooMgr(const FooMgr &);
FooMgr &operator=(const FooMgr &);
public:
FooMgr() { }
~FooMgr() { }
void Destroy(void)
{
for (unsigned int i=0;i<FooVector.size();i++)
{
if (FooVector[i]) delete FooVector[i];
}
FooVector.clear();
}
bool GetValue(unsigned int uID,int iOffset,int &iOutValue)
{
if (iOffset>FooVector[uID]->GetSizeOfArray()) return true;
iOutValue=FooVector[uID]->GetValue(iOffset,iOutValue);
return false;
}
.....
};
This makes vectors very easy to use and great for resource managers.