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 |
The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this
how c source file in converted to exe file
What would be an example of a structure analogous to structure c?
please tell me the logic for this C program : INPUT (string):ABCD OUTPUT :BCDA CDAB DABC
What is true about the following C Functions a.Need not return any value b.Should always return an integer c.Should always return a float d.Should always return more than one value.
What is a structural principle?
Given an unsigned integer, find if the number is power of 2?
how to get starting address of a running C program
What is the difference between null pointer and wild pointer?
What’s the special use of UNIONS?
N O S I E R + A S T R A L ---------------- 7 2 5 6 1 3
Write a program to print fibonacci series without using recursion?