Need a sample

Ok, I need just a small example that defines a class that has public, private, and protected members. If I have a visual then I can better understand and write my own code. Any takers?
1
2
3
4
5
6
struct Class
{
    public: int a;
    protected: int b;
    private: int c;
};


Or do you mean a real-world example?
Real-world would be good, but it doesn't need to be extensive. Just something simple, I'm a newbie at this.
1
2
3
4
5
6
7
8
9
10
11
12
class human
{
public:
  string askForName();
private:
  string name;
};

string human::askForName()
{
  return name;
}


I hope this is a good example of a class.
The name is private and another person who "talks" to this object needs to ask for name before he can know it. Basicly you just dont want some things to change things like name if they are not supposed to do it.

And if you think of it like a real world situation you cant change the name of another person right?

Hope this helped, wish you best luck!
Topic archived. No new replies allowed.