c++ - how to write the definition for this method i am getting error -


thanks in advance trying write definition method

customer* getmemberfromid(std::string); 

this definition wrote getting error saying [error] 'customer' in 'class store' not name type

store:: customer* getmemberfromid(std::string id) {     for(int = 0; < members.size(); i++)     {         customer* c = members.at(i);         if(c->getaccountid() == id)         {              return c;         }     }     return null; } 

try

customer* store::getmemberfromid(std::string const& id) 

hard full minimal, complete, , verifiable example (which should provide), i'm guess getmemberfromid member function of store, customer not member of store, , got confused naming rules.

note swapped (std::string id) (std::string const& id) avoid copy of string, when didn't need it.

then use standard algorithm find_if:

customer* store::getmemberfromid(std::string const& id) {     auto foundpos = std::find_if(members.begin(),                                  members.end(),                                  [&](customer* c){ return c->getaccountid() == id; });     return (foundpos==members.end())                 ? nullptr                 : *foundpos; } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -