| | |
C++ conceptual question
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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.
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.
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.
![]() |
Similar Threads
- C command-line I/O question (C++)
- Completely new to C++ and have question about using char (C++)
- question on cooling (Cases, Fans and Power Supplies)
- Context-sensitive grammar question :( (Computer Science)
- Welcome PC Mod Kingdom peeps! (Geeks' Lounge)
- Laptop LCD built into a car? (Monitors, Displays and Video Cards)
- Changing Network Configuration (*nix Software)
Other Threads in the C++ Forum
- Previous Thread: Visual C++ 2005 question
- Next Thread: Overloading the increment operator plz help
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






