In C++, this optional keyword starts declaring the private data members and/or member functions. The private members of a class are minimally accessible by other program parts.

It is invoked thus:

class foo
{
public:
//

protected:
//
private:
protected data members
protected member functions

}

The private section contains data members and member functions that are not accessible to class instances, to descendant classes, or to functions that do not belong to the class (such as the main() function). Typically, the private section contains highly sensitive data members and auxiliary member functions. Highly sensitive meaning data members that should work only with the private member functiosn of the calls. In other words, the private data members are conceptually "top secret" and should be handled by member functions that are themselves private.

Private is also a swedish porn company. Perhaps most famous for their uranus project.
The porn movies from Private that i've seen, were all of a poor quality, meaning that the cutting was bad, the cameramen were lousy and the directing nonexisting. Othervise the actors were beautiful and the scenery often amazing.

A Private is also the lowest ranking soldier in the United States Army and Marine Corps. His pay grade is that of an E1 or E2, the difference being an E1 is that you are a fresh-outta-boot camp recruit, with no insignia. After about 4-6 months of service, you are automatically promoted to Private E2. You then wear a standard triangular stripe (chevron) on your uniform, making you a full Private.

C++ class member visibility:

In C++, members of the "private:" section(s) of a class (or struct) definition are visible only within members of that class. Outside that class, they are inaccessible, and cannot be used. In effect, the scope of their declaration does not extend beyond the class -- and C++ won't let you use something with no declaration in scope!

The following code snippet shows some of the behaviour. Lines with comments starting "*" are compilation errors; since we're discussing visibility, we must show them.

class X {
private:
  int a;
  int square() {
    return a*a;            // OK (1)
  }
  X(const X& y);           // Code outside class cannot invoke
                           // copy constructor.
public:
  X(int val) : a(val) {}
  int& add(const X& y) {
    return a += y.a;      // OK (1)
  }
};

class Y : public X {
private:
  void print() {
    std::cout << a;        // * NOT OK (2)
  }
};


X quadruple(X x)           // * NOT OK (3)
{
  x.add(x);
  x.add(x);
  return x;                // * NOT OK (3)
}

void f() {
  X a(2);                  // OK (4)
  X b(3);
  X c(a);                  // * NOT OK (5)
  a.add(b);                // OK
  std::cout << a.a;        // * NOT OK (6)
  std::cout << a.square(); // * NOT OK (6)
}

Notes:

  1. A member function of X may access private: members. Note that visibility is phrased in terms of the class, not in terms of the object. Thus, X::add(const X&) can see not just its own a (this->a), but also y.a. There is no way (in C++) to prevent this: visibility is not related to instances.
  2. The class of Y is not the class of X. (Contrast this to the fact that an instance of Y is an instance of X!) private: members of X are not visible in Y. You need protected: for that.
  3. X has a private: copy constructor. So code outside it cannot pass X parameters, and cannot receive X return values. Thus, quadruple cannot be used. The implicit use of the copy constructor is enough to break it.

    If you must pass such an X to a function, you can use a reference, which requires no copy.

  4. You can create an X from an int using its public constructor.
  5. You also cannot explicitly call X's copy constructor.
  6. And, of course, direct access to X's private parts is forbidden.

The default visibility of a class is private: (this is the only difference between it and struct).

Finally, note that nested classes aren't "inside" their containing class; a class X::Foo would also be unable to use private members of X.

C++ inheritance visibility:

You may also declare an inheritance relation between two classes "private". It is very similar to private: visibility of members: only member functions of the class may use that inheritance. But of course, even they are bound by the visibility of the parent class' methods (just like Y was, in the previous example).

This is hardly "inheritance" in the sense of an "is-a" relationship, at least not outside the class. But that's the whole point: anything outside the implementation cannot tell (from external behaviour) that the inheritance exists. Thus, private inheritance is sometimes used to model a "has-a" relationship; it is unclear whether this offers any benefits over having a member of the appropriate type.

Pri"vate (?; 48), a. [L. privatus apart from the state, peculiar to an individual, private, properly p. p. of privare to bereave, deprive, originally, to separate, fr. privus single, private, perhaps originally, put forward (hence, alone, single) and akin to prae before. See Prior, a., and cf. Deprive, Privy, a.]

1.

Belonging to, or concerning, an individual person, company, or interest; peculiar to one's self; unconnected with others; personal; one's own; not public; not general; separate; as, a man's private opinion; private property; a private purse; private expenses or interests; a private secretary.

2.

Sequestered from company or observation; appropriated to an individual; secret; secluded; lonely; solitary; as, a private room or apartment; private prayer.

Reason . . . then retires Into her private cell when nature rests. Milton.

3.

Not invested with, or engaged in, public office or employment; as, a private citizen; private life.

Shak.

A private person may arrest a felon. Blackstone.

4.

Not publicly known; not open; secret; as, a private negotiation; a private understanding.

5.

Having secret or private knowledge; privy.

[Obs.]

Private actstatute, a statute exclusively for the settlement of private and personal interests, of which courts do not take judicial notice; -- opposed to a general law, which operates on the whole community<-- also, private law vs. public law -->. -- Private nuisancewrong. See Nuisance. -- Private soldier. See Private, n., 5. -- Private way, a right of private passage over another man's ground.<-- also, a road on private land, contrasted with public road. -->

Kent.

 

© Webster 1913.


Pri"vate (?), n.

1.

A secret message; a personal unofficial communication.

[Obs.]

Shak.

2.

Personal interest; particular business.

[Obs.]

Nor must I be unmindful of my private. B. Jonson.

3.

Privacy; retirement.

[Archaic] "Go off; I discard you; let me enjoy my private."

Shak.

4.

One not invested with a public office.

[Archaic]

What have kings, that privates have not too? Shak.

5. Mil.

A common soldier; a soldier below the grade of a noncommissioned officer.

Macaulay.

6. pl.

The private parts; the genitals.

In private, secretly; not openly or publicly.

 

© Webster 1913.

Log in or register to write something here or to contact authors.