using vector in private class?

I am trying to use the vector m_Gamers declared in the private class using FindorInsert to compare strings. Is that even possible? Is there another way of using it, maybe doing a copy?. I'm sorry if this is a noob question, i'm quite knew to this. any help is appreciated :) thank you

1
2
3
4
5
6
7
private:
	std::vector<Gamer> m_Gamers;
        int FindorInsert(const std::string& name);
In C++ File:
     int FindorInsert(const std::string& name){
     here I try to access m_Gamers to compare with name but i can't 
    } 
Last edited on
In that "In C++ File" you need to properly scope that function as a member of the class. What you've shown is a global (non-class function) not a class member function.

We need more context.

The error messages which tell you there's a problem, the actual code that attempts access.

Without full vision, we can only guess.

That said, not only is it possible, it should be trivial.

However, the "in C++ file" portion of your post does not include the class name before FindorInsert, so I'd expect THAT to be a problem.

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// In your header file
struct gamer
{ 
  std::string name_; 
};

struct multiplayer_lobby
{
  bool has_gamer_named(std::string const& name) const;

private: 
  std::vector <gamer> gamers_;  
};

// In your implementation file
bool multiplayer_lobby::has_gamer_named(std::string const& name) const
{
  for (gamer const& g: gamers_)
    if (g.name_ == name) 
      return true;
  return false;
}
Last edited on
That makes a log of sense! who knew it would be that simple -__-

Thank you 1000
Topic archived. No new replies allowed.