Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Classes
#4
By default, member variables and functions are public. They can be accessed like

Macro
Code:
Copy      Help
CRect r
r.m_width=15

To protect member variables from accessing from outside of the class, in class definition add one or two hyphens before these members:

Macro
Code:
Copy      Help
class CRect
,-double'm_width ;;m_width is protected. It can be used only in functions of CRect and inherited classes (eg CColorRect).
,--double'm_height ;;m_height is private. It can be used only in functions of CRect class.

Now r.m_width=15 would generate error.

You also can protect some member functions from callig from outside the class. You can do it in function's Properties dialog.

To hide member variables and functions without protecting, let the variable/function name begin with __. Examples: __m_hidden, CRect.__Hidden. Or place the functions in a folder that has 'private functions' checked in Folder Properties dialog.


Messages In This Thread

Forum Jump:


Users browsing this thread: 7 Guest(s)