It may be nice to not impose a particular type of container (like std::vector) on the callers of the int MyClass::MyString method. Sometimes, I like to make these types of methods templatized on an iterator type like this:
template< class IteratorType >
int MyClass::MyString(const IteratorType &iterBegin, const IteratorType &iterEnd)
{
// Get a count of items passed in.
const size_t nNumItems = iterEnd-iterBegin;
// Iterate over the input
IteratorType iter;
for(iter = iterBegin; iter != iterEnd; ++iter)
{
// Do something here.
}
}
template< class IteratorType >
int MyClass::MyString(const IteratorType &iterBegin, const IteratorType &iterEnd)
{
// Get a count of items passed in.
const size_t nNumItems = iterEnd-iterBegin;
// Iterate over the input
IteratorType iter;
for(iter = iterBegin; iter != iterEnd; ++iter)
{
// Do something here.
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks