I have an vector, filled with objects:
std::vector<MyClass> vec;
vec.push_back(MyClass("Hi", 10)); //example, could be any class
Later, when it is filled, I want to access it:
for(unsigned int i = 0; i < vec.size(); i++)
{
MyClass *c = & vec.at(i); // <--- HERE
if(c) // <--- AND HERE
{
c->memberOfMyClass = x;
}
}
Is using c more dangerous than using vec.at(i) directly? Do I need the protection with if(c)? Can c be nullptr? I guess no, because the vector does take object, not pointer to objects.