AngelScript

Private class members

Class members can be declared as private if you do not intend for them to be accessed from outside the public class methods. This can be useful in large programs where you wish to avoid programmer errors where properties or methods are inappropriately used.

      // A class with private members
      class MyPrivate
      {
        // The following are public members
        void PublicFunc()
        {
          // The class can access its own private members
          PrivateProp = 0; // OK
          PrivateFunc();   // OK
        }

        int PublicProp;

        // The following are private members
        private void PrivateFunc()
        {
        }

        private int PrivateProp;
      }

      void GlobalFunc()
      {
        MyPrivate obj;

        // Public members can be accessed normally
        obj.PublicProp = 0;  // OK
        obj.PublicFunc();    // OK

        // Accessing private members will give a compiler error
        obj.PrivateProp = 0; // Error
        obj.PrivateFunc();   // Error
      }