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 |
What is static function in c?
Explain the process of converting a Tree into a Binary Tree.
What is the output of following program ? int main() { int x = 5; printf("%d %d %d\n", x, x << 2, x >> 2); }
How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?
const char * char * const What is the differnce between the above tow?.
What is a double c?
difference between c and c++?
How can you pass an array to a function by value?
What should malloc() do? Return a null pointer or a pointer to 0 bytes?
Write a program to give following output..... ********* **** **** *** *** ** ** * * ** ** *** *** **** **** *********
Write a program with dynamically allocation of variable.
write a program to search for an element in a given array. If the array was found then display its position otherwise display appropriate message in c language