SO vote to reopen: protected visibility

jdavidb on 2009-10-09T19:23:19

Somebody give me some tips on how to reword this to make it a "real question."


I'm with chaos

jarich on 2009-10-10T10:03:07

I'm not much of a Stackoverflow user. However it doesn't strike me as a place designed to handle opinion-based questions. chaos' suggested rewrite:

what reasons are there to use protected members and/or to avoid them?

seems a little better, but I think the question still needs to be more detailed. Perhaps something along the lines of:

I have a class (X) and its child class (X::Y). X has a variable Z for some purpose. It doesn't make sense (for some reason) to make Z an attribute of X::Y but X::Y still needs to be able to access Z. I could implement it as a protected member, or I could expose it some other way. What is the correct approach in this situation and why?

I think the problem with your original question is that it is scope-less. Protected variables have some advantages and some disadvantages. However it's difficult to answer with something that would be relevant to the question because it's too hard to guess what you were thinking when you wrote it.