:
class MyClass {
public:
const unsigned int GetNumberOfItems() { return v.size(); }
T* GetItemNumber(const unsigned int n)
{
try{
return v.at(n);
} catch (std::out_of_range &e){
}
return NULL;
}
vector<T> v;
};
- :
MyClass cl;
int count = cl.GetNumberOfItems();
for (int i = 0; i < cl.GetNumberOfItems(); i++){
T* item = cl.GetItemNumber(i);
}
No iterators in the outside world are required. If you've ever had to expose something like the standard C API, then it's very easy to expose.
source
share