Alex Rivera | Logout

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

Asked 2008-10-22T09:11:21.937
376

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?

Edit
Report

1 Answer

6

Sure take a look at the Protected Member Variables question. It is recommended to use private as a default (just like C++ classses do) to reduce coupling. Protected member variables are most always a bad idea, protected member functions can be used for e.g. the Template Method pattern.

answered 2008-10-22T09:48:07.650

Your Answer