lundi 2 septembre 2019

difference in for each loop

I am trying to use for each loop in c++.

this->Functions is a vector.

std::vector< std::shared_ptr<Sum_Function> > Functions;

After reading i came across two different ways to do for each.

bool Container::HasFunction(std::string stdstrFunctionName )
{
    for (auto &func : this->Functions)
    {
        if (func->getFunctionName() == stdstrFunctionName)
            return true;
    }
    return false;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for (auto func = this->Functions(); func != this->Functions(); ++func)
{  
    if (func->getFunctionName() == stdstrFunctionName)
    return true;
}

my question is that these both are nearly doing the same stuff , is there any difference between the two.

Or just different flavors for the same thing.

Aucun commentaire:

Enregistrer un commentaire