How does C++ help with the tradeoff of safety vs. usability?
Answer / abalonesoft
In C, encapsulation was accomplished by making things static
in a compilation unit or module. This prevented another
module from accessing the static stuff. (By the way, static
data at file-scope is now deprecated in C++: don't do that.)
Unfortunately this approach doesn't support multiple
instances of the data, since there is no direct support for
making multiple instances of a module's static data. If
multiple instances were needed in C, programmers typically
used a struct. But unfortunately C structs don't support
encapsulation. This exacerbates the tradeoff between safety
(information hiding) and usability (multiple instances).
In C++, you can have both multiple instances and
encapsulation via a class. The public part of a class
contains the class's interface, which normally consists of
the class's public member functions and its friend
functions. The private and/or protected parts of a class
contain the class's implementation, which is typically where
the data lives.
The end result is like an "encapsulated struct." This
reduces the tradeoff between safety (information hiding) and
usability (multiple instances).
| Is This Answer Correct ? | 3 Yes | 0 No |
Write a program to show the change in position of a cursor using c
What are nested functions in c?
What is the method to save data in stack data structure type?
a=(1,2,3); b=1,2,3; c=1,(2,3); d=(1,2),3; what's the value of 'a','b','c','d'
What is the full form of getch?
write a function that accepts an array A with n elements and array B with n-1 elements. Find the missing one in array B,with an optimized manner?
What is an example of enumeration?
can we declare a function in side the structure?
How to receive strings with spaces in scanf()
Ow can I insert or delete a line (or record) in the middle of a file?
What is a stream water?
Using functions, write a program that multiplies two arrays. Use the following functions: - Function ReadArray - Function MultiplyArrays - Function DisplayArrays