Public?

Public keeps poping up in things I read like this

1
2
3
4
5
6
class Firework : public cyclone::Particle
{
public:

cyclone::real age;
};


does public have a particular meaning in c++?
Yes. I suggest you go over to
http://www.parashift.com/c++-faq-lite/
and read through the sections on inheritance.

Public is stuff that things outside of a class can see. For example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Duo
{
  public:  int visible;
  private: int invisible;

  public:
    void set_invisible( int v ) { invisible = v; }
};

...

int main()
{
  Duo d;
  d.visible  = 42;  // OK
  d.invisible = 42;  // fails. (I'm not allowed to touch this directly!)
  d.set_invisible( 42 );  // OK (The object can do whatever it likes to its own stuff.)
}


Inherited objects should almost always be inherited as 'public'. Read the C++ FAQ Lite section 24 for more.

Hope this helps.
Okay thanks for clearing that one up :D
Topic archived. No new replies allowed.