Hello all,

While I understand what the class access keywords public, private, and protected are supposed to do, I just don't see how this ACTUALLY "hides variables" and makes for more bullet proof code.

Do the variable names survive the compilation process?
If someone was to read compiled code in raw memory, would they see the variable names?

Also, the process of taking one variable name in a public funtion, and then assigning it's value to a private variable seems redundant and a bit convoluted to me.

Also the concept of 'constant functions" seems contrived. What is really happening with that?
A function can have a constant and non constant version just by virtue of class definition?

If some program went awry, wouldn't that 'constant" piece of code get "stepped on"? After all, both are just memory locations! I don't fully appeciate the difference.

Perhaps I'm just "thinking into it" too much, but I do like to understand what I'm doing and WHY.

Thanks in advance for any light you can shed on this.

>>Do the variable names survive the compilation process? If someone was to read compiled code in raw memory, would they see the variable names?
No. Compiled porgrams know nothing about variable names -- they are all nothing more than addresses. Variable names are only for you, the human programmer.


>>Also, the process of taking one variable name in a public funtion, and then assigning it's value to a private variable seems redundant and a bit convoluted to me

This has the advantage of allowing only one place in the program to change the value of a class variable. If you later want to change the way the variable is used the programmer has to make the change in only one place.

>>Also the concept of 'constant functions" seems contrived. What is really happening with that?

const tells you and the compiler that the object can not be changed or that the const function is not going to change any data objects of the class. It has no affect on the code itself, but is a retraint on you, the programmer, not to mess around with class objects -- class objects are read-only. Also, a const class method can only call other const methods of the same class.

>>If some program went awry, wouldn't that 'constant" piece of code get "stepped on"? After all, both are just memory locations! I don't fully appeciate the difference

Const is a compile-time restriction. It has no affect at run-time; the compiled program knows nothing about the const keyword. All const problems must be resolved at compile time, so at runtime there will never be any such problems.

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.