What is the difference between private and protected members of C++ classes?

What is the difference between private and protected members in C++ classes? I understand from best practice conventions that variables and functions which are not called outside the class should be made private—but looking at my MFC project, MFC seems to favor protected. What’s the difference and which should I use? 19 Answers 19

What is the difference between public, private, and protected?

When and why should I use public, private, and protected functions and variables inside a class? What is the difference between them? Examples: // Public public $variable; public function doSomething() { // … } // Private private $variable; private function doSomething() { // … } // Protected protected $variable; protected function doSomething() { // … … Read more

What is the difference between public, protected, package-private and private in Java?

In Java, are there clear rules on when to use each of access modifiers, namely the default (package private), public, protected and private, while making class and interface and dealing with inheritance? 30 30 The official tutorial may be of some use to you. Class Package Subclass(same pkg) Subclass(diff pkg) World public + + + … Read more