Can someone explain to me, the purpose of the "public" and "private" options of a class?

ZlapX commented: sucks balls +0

Recommended Answers

All 12 Replies

It seems like you just wan't to ask question and not do any reasearch,
i.e be lazy. Did you think google did not have an answer to this
question? Google has answers to all. Here is a answer to your question.

They control how accessible the members of a class are. It's a pretty easy google search.

Read this for more information.

edit:
looks like firstPerson beat me to it...

It seems like you just wan't to ask question and not do any reasearch,
i.e be lazy. Did you think google did not have an answer to this
question? Google has answers to all. Here is a answer to your question.

How do you know if i've done research or not!?! I am in a Intermediate C++ and just didn't get the topic as it was explained.

How do you know if i've done research or not!?! I am in a Intermediate C++ and just didn't get the topic as it was explained.

That just means you sat through the discussion. But did you listen? The answer is a quick google search away.

This is the reason for the response you got.

commented: sucks balls +0

Honestly, I'm out googling for the same answer, there's lots of "How" and "What", but doesn't seem to be any "Why". How I long for Pokes, Peeks and Geeks who love to share knowledge with anyone who takes interest rather than the LMGTFY and RTFM crowd. Damn you Wargames for making geeks dangerous and attitudinal.

To answer to the OP I had to ask an old school geek for and he shared his time and information willingly... all after I had googled the what and how of it. It protects programmers from accidentally forgetting the scope of all the variables they've declared in their complicated OOP structures for their programs (not always a bad thing). They aren't necessarily necessary and they're utility is in the eye of the beholder. If you're writing code for others who expect to see the scopes wrangled in this manner, then you should use them. If you find them useful, then you should use them. If you don't see the reason behind hiding parts of functions from the rest of the code you're writing (or others in your team - distributed coding would be a great reason for these restrictions), then don't use them.

-> Replacing a CPU used to take a soldering iron, my Dad taught me how to do that... Someone helped you when you were starting, pay it forward - the dividends are immense.

It's not that we're unwilling to help. In fact, far from it...

Many times, a response containing a link to LMGTFY is the best way to answer the question. Google, or whichever search engine you prefer, is a powerful research tool when someone takes the time to use it and uses it properly. The intent of such links is to teach them how to do their own research, not belittle or berate them.

If you look through the site more thoroughly you will find that when their own research comes up short and they can demonstrate a conscientious effort to do the research, they'll find the flood gates wide open when they ask a reasonable question that a member is able to answer. That being said, I also want to stress that the language a person uses in their post is very telling to the experienced poster. It is very obvious when a poster is truly stuck or just being lazy. If they're just being lazy, they're going to get lazy responses.

I did read the document about how to ask hackers questions... I see a disconnect with the reality of the content of the document. Taking the time to accuse someone of being a timesink is much less efficient than simply ignoring the question.

The google links provided above were fundamentally the same ones I had read and none of them answered the question I had about this topic. The initial question, although lacking a bit in specificity, displayed an immediate knowledge of a programming topic that is slightly beyond basics (pun intended). Perhaps the interpretation of the initial question lead to the knee jerk "idiot must not know how to use google" reaction above.

The google search sent me here as well as the other sites I was reading. This thread was more lacking in information for my google search than the other hits I found, which still didn't answer my question. What it did was give me a sour first impression of your community... which I assumed was false based on the frequency with which I've seen this same type of reaction to questions that the respondent perceives as a "Bad" question on so many other boards on so many other topics (not just programming or computers). The warm welcome in the e-mail I received is most likely true in the statement/goal "Welcome to DaniWeb, the friendliest IT discussion community on the web!"... but this first impression thing is really a bugger. I subscribed to the community simply to answer the poor OP's question to the best of my ability.

So I believe that you're perfectly willing to help, but as an introduction to your community, I feel a bit put off by the reaction to the OP. Perhaps if they had begun with, "I'm stuck..." or "I've googled and come up empty..." or "Here's my question, which you will read one way, but I really mean this different way as the howto stuff I've found through the google searches aren't the resolution I seek..."

Although, I fully understand the function and implementation of OOP, I still haven't seen a compelling reason to commit fully to it. Seems to me to simply be a way to stress that programming is fundamentally unapproachable by new and curious users. The same tasks can be completed in much simpler and more efficiently committed to code than current practices would have them. As a programmer who has watched programming become much less efficient in both time consumed, code complexity and machine resources... it seems to me to serve the same purpose as the Jargon laden speech of other disciplines - to keep the outsiders out which is counter to the original dream of computing... to make life easier for people. BASIC, Applescript, Hypercard, FORTRAN although scoffed at by "proper" programmers, are the basis upon which programmers were made for the last 30-40 years... before that, you needed to learn assembly to program (which wasn't that bad due to the fact that there were an extremely limited set of commands to learn - the logic just wasn't handled by the language and obfuscated from the programmer like it is now).

I'm now completely off-topic for which I apologize. I was raised by and married an educator (not the same person). People seeking answers and not finding them tends to get my lather up. Remember, there is no context on the internet, questions don't have body language or history without explicit statement. The web ruined the net's function as a communication device due to the influx of people who had net netiquette, but striking back at them compounds the problem. The person you answer a ridiculous question for today could hire you tomorrow, you never know.

And that will be the end of my rant. I don't need you to agree with my vantage point, I just wanted you to know it exists. Sorry for carrying on, carry on.

I understand your concern, and I tend to agree with your general opinion. I was trying to give you the "why" :P Believe me, it is possible to get into programming if you have the right resource(s). Do you see my join date? It's less than a year ago. It was only a month or 2 before that that I started in programming, so maybe a year ago. Your local library is actually a pretty good resource believe it or not, if yours uses the Dewey Decimal system, go to section 005.1xx. You'll be surprised how much you find there.

Did you read the first of the 2 links that I posted? That link is a direct link to a page describing the syntax of a C++ class definition, it is not a LMGTFY.

There isn't much "why" in language-specific tutorial literature because the authors assume that if you know anything at all about OOP, you probably already know the why. They assume that if you are reading that type of document, you are trying to learn the "how", so that's what they give you.

The access specifiers "public", "protected", and "private" are related to the OOP concepts of "encapsulation" and "inheritance". Try researching "OOP encapsulation" as well as "goals of OOP". Those 2 searches should get you alot of information about the "why".

A book that I read that helped me understand OOP better was "Object Oriented Design Heuristics" by Arthur Riel. It is a mostly language-neutral guide to the concepts behind OOP and designing your software to be as OOP friendly as possible. What it is not is a stringent design process, it allows you to decide what process best suits you.

Unless you think we can focus on the OP's topic, I think at this point it might be best if you started a new thread. We've bumped this one enough times with posts that are not relevant to the OP.

Thanks for the info on the "Why"... I'll certainly read into those.

The other comments weren't geared toward you, they were geared toward the other poster (who's timbre in connection with their start date and # of posts seem to undercut the "friendly" mission of the site a bit) who, as a first response, accused the poster (who had been a member for 4 months and currently has 169-ish posts by this point) of being lazy and straight to the LMGTFY link which is meant to be condescending.

I love my library's computers/programming section and have spent quite a bit of time there. Searching for technical answers is much simpler than searching for the esoteric why answers, so I thank you for your google hints toward that end.

I agree that I've derailed the discussion and apologize for that. I'll gladly consider this thread rested as you've provided great references toward the why's.

...The other comments weren't geared toward you, they were geared toward the other poster (who's timbre in connection with their start date and # of posts seem to undercut the "friendly" mission of the site a bit) who, as a first response, accused the poster (who had been a member for 4 months and currently has 169-ish posts by this point) of being lazy and straight to the LMGTFY link which is meant to be condescending.
...

I know... But, I think you need to get to know firstPerson better before making too many judgements, he's actually a pretty good guy. Once you have been around longer, and experienced your fair share of "givemethecodez" type responses, you'll understand his response.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.