What does my example ?
See the question in my last message - how would you make 'hd' private
and 'tl' public, while leaving them all inside struct 'list'?
Because when someone (me for example) want to use the library he
reads the .h (or .hpp with c++) and he know which objects (struct)
exist and which function exist (an API reference), I don't want him
to see a function that he hasn't to use. If he want to use an
internal function, he can but it's his problem, not mine.
This isn't how programming languages generally work, they're not
supposed to be closed because let's face it, a bunch of text files isn't
really that secure. If someone is determined to see how your code works
they'll figure it out eventually. Hiding code like this will only trick
you into thinking it's secure.
I don't use protected (it's useless).
I find it quite useful myself. I suspect you've never come across a
problem that could be solved with the use of protected members
I don't want him to know how work my class in internal, because it
could change if I use a new method (new algorithm, I change an int
into a char etc.), but I never change the public (it's a fundamental
principle).
This is the whole idea behind private members. You're not supposed to
use them because they could change without warning. It doesn't matter
whether you can see them or not, only a foolish programmer would
'illegally' use somebody else's private data members. It's like an
honesty system - you're telling people not to use the private members,
and if they go ahead and use them, then it's their own fault when you
change something and their code breaks. Serves them right for ignoring
you
And I don't want him to see the internal of my class. I'm a part of
guys who think that look at the source code of others is heretical.
Then I feel sorry for you
Sharing source code is amazingly
productive, you can learn a huge amount from reading someone else's
code. Not sharing source code is like painting an amazing picture and
then refusing to show it to anyone - how can people respect your skill
as a programmer if they can't see your code?
If you don't want people to see your code, then the safest way is to
simply not write any classes - that's the only way you can guarantee
that nobody will see your code ;-)
(or you could use abstract base classes, as has already been suggested:
http://www.parashift.com/c++-faq-lite/abcs.html)
Cheers,
Adam.