CArray::GetUpperBound() is used to get the UpperBound of the array(last index of the array).
Because array indexes are zero-based, this function returns a value 1 less than GetSize.
GetUpperBound( ) give –1 when array contains no elements.
CArray<cpoint,cpoint> myArray;
CPoint pt;
for (int i = 0; i < 10; i++)
myArray.Add(CPoint(i, 2 * i));
for (int i = 0; i <= myArray.GetUpperBound(); i++)
{
pt = myArray.GetAt(i);
pt.x = 0;
myArray.SetAt(i, pt);
}
CArray::GetSize() return the size off array.Because indexes are zero-based, the size is 1 greater than the largest index. Calling this method will generate the same result as the CArray::GetCount method.
CArray<cpoint,cpoint> myArray;
for (int i = 0; i < 10; i++)
myArray.Add(CPoint(i, 2*i));
for (int i = 0; i < myArray.GetSize(); i++)
{
CPoint& pt = myArray.ElementAt(i);
pt.x = 0;
}
You can call size() function for Vectors.
#include <iostream>
#include <vector>
int main ()
{
std::vector<int> myints;
std::cout << "0. size: " << myints.size() << '\n';
for (int i=0; i<10; i++) myints.push_back(i);
std::cout << "1. size: " << myints.size() << '\n';
myints.insert (myints.end(),10,100);
std::cout << "2. size: " << myints.size() << '\n';
myints.pop_back();
std::cout << "3. size: " << myints.size() << '\n';
return 0;
}