Private members are only accessible within the class defining them.
Protected members are accessible in the class that defines them and in classes that inherit from that class.
Edit: Both are also accessible by friends of their class, and in the case of protected members, by friends of their derived classes.
Edit 2: Use whatever makes sense in the context of your problem. You should try to make members private whenever you can to reduce coupling and protect the implementation of the base class, but if that’s not possible then use protected members. Check C++ FAQ for a better understanding of the issue. This question about protected variables might also help.
Related Posts:
- Understanding Python super() with __init__() methods [duplicate]
- When should you use a class vs a struct in C++?
- C++ [Error] no matching function for call to
- Separating class code into a header and cpp file
- Error “C++ requires a type specifier for all declarations whilst defining methods”
- What are the differences between struct and class in C++?
- How do I define string constants in C++?
- C++ variable has initializer but incomplete type?
- C++ – No appropriate default constructor available
- What is predicate in C++?
- How do you implement a class in C?
- C++ classes (public, private, and protected)
- Error: invalid use of member in static member function
- What does the variable $this mean in PHP?
- What is the purpose of the word ‘self’?
- Is it possible to make abstract classes in Python?
- Expression must have class type
- C++ error ‘Undefined reference to Class::Function()’ [duplicate]
- Using two CSS classes on one element
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- Why is enum class preferred over plain enum?
- How to assign multiple classes to an HTML container?
- What does ‘super().__init__()’ mean in python 3.x?
- How to assign multiple classes to an HTML container?
- Reading from file in c++ ifstream
- Why am I getting this redefinition of class error?
- Are static class variables possible in Python?
- Single class has a Class Redefinition Error
- C++ Linked List Node with class
- (->) arrow operator and (.) dot operator , class pointer
- Is C++ an Object Oriented language?
- Does Python have “private” variables in classes?
- Python: How do I make a subclass from a superclass?
- how to define -std=c++11 as default in g++
- Pointer to incomplete class type is not allowed
- Why am I getting this redefinition of class error?
- Difference between ‘cls’ and ‘self’ in Python classes?
- no default constructor exists for class
- Error at constructor : Expected an identifier?
- Getting error “a nonstatic member reference must be relative to a specific object” while both member are in the same class
- C++ BlackJack Stuck trying to program Ace
- error C2011: ” : ‘class’ type redefinition
- When should I use ‘self’ over ‘$this’?
- How to implement a binary search tree in Python?
- The compiler is complaining about my default parameters?
- Already defined in .obj – no double inclusions
- C++ Linked List Node with class
- Getting error: ISO C++ forbids declaration of with no type
- fatal error LNK1169: one or more multiply defined symbols found in game programming
- How to call a parent class function from derived class function?
- “used without template parameters”
- Python function overloading
- expected constructor, destructor, or type conversion before ‘(’ token
- C++ Class ‘undeclared identifier”
- c++ “Incomplete type not allowed” error accessing class reference information (Circular dependency with forward declaration)
- Base class undefined
- Warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11?
- What is the meaning of a C++ Wrapper Class?
- Does C++11 have C#-style properties?
- G++ undefined reference to class::function
- Creating an instance of class
- Why do some classes require main methods and others do not?
- Pass arguments to Constructor in VBA
- uml classdiagram constructor with parameters
- expected primary-expression before ‘]’ token
- When/why to make function private in class?
- Does C have classes?
- error C2039: ‘string’ : is not a member of ‘std’, header file problem
- istream and ostream problem – C++
- Struct with template variables in C++
- error: no member function declared in class
- Here is some error with my .h file which show [Error] unterminated #ifndef when I include my class template in it
- How can I design a class named allergy?
- C++ equivalent of java’s instanceof
- How to correctly use Boolean functions?
- C++ Error: “Expression must have integral or enum type” [duplicate]
- c++ compile error: ISO C++ forbids comparison between pointer and integer
- How do I declare a 2d array in C++ using new?
- Why does the C++ STL not provide any “tree” containers?
- Compiling C++11 with g++
- Setting an int to Infinity in C++
- dynamic_cast and static_cast in C++
- What exactly is std::atomic?
- How to ensure that a std::map is ordered?
- How to write C++ getters and setters
- std::out_of_range error?
- Center text in fixed-width field with stream manipulators in C++
- ctypes error: libdc1394 error: Failed to initialize libdc1394
- Understanding glm::lookAt()
- How to get current timestamp in milliseconds since 1970 just the way Java gets
- Cannot open output file, permission denied
- Strange error C2131: expression did not evaluate to a constant in VC 2015
- When to use const char * and when to use const char []
- What is wrong with using goto?
- Double pointer array in c++
- error: ISO C++ forbids in-class initialization of non-const static member
- Function call missing argument list to create pointer
- cannot specify explicit initializer for arrays
- What does ** mean in C++?
- Incomplete type is not allowed: stringstream