So I'm working with a function that returns a pointer to a list item. Right now, I'm using:
IYamlEntity* YamlList::operator[](int key)
{
// Check for out-of-bounds.
if (key < 0 || key >= _items.size()) return nullptr;
return &(_items[key]); // **<- Line of interest.**
}
Would the following be better?
IYamlEntity* YamlList::operator[](int key)
{
// Check for out-of-bounds.
if (key < 0 || key >= _items.size()) return nullptr;
return (_items + key); // **<- Line of interest.**
}
I know that they're functionally identical, but which one is "best practice"?