C++ conceptual question

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 231
Reputation: JRM will become famous soon enough JRM will become famous soon enough 
Solved Threads: 14
JRM's Avatar
JRM JRM is offline Offline
Posting Whiz in Training

C++ conceptual question

 
0
  #1
Oct 31st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,618
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1491
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: C++ conceptual question

 
0
  #2
Oct 31st, 2006
>>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.
Last edited by Ancient Dragon; Oct 31st, 2006 at 11:39 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC