How does C++ help with the tradeoff of safety vs. usability?



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

Post New Answer

More C Interview Questions

The postoder traversal is 7,14,3,55,22,5,17 Then ur Inorder traversal is??? please help me on this

1 Answers  


how c source file in converted to exe file

5 Answers   KPIT,


What would be an example of a structure analogous to structure c?

0 Answers  


please tell me the logic for this C program : INPUT (string):ABCD OUTPUT :BCDA CDAB DABC

2 Answers   Mphasis,


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.

11 Answers   TCS,






What is a structural principle?

0 Answers  


Given an unsigned integer, find if the number is power of 2?

5 Answers  


how to get starting address of a running C program

3 Answers  


What is the difference between null pointer and wild pointer?

0 Answers  


What’s the special use of UNIONS?

0 Answers   ADP,


N O S I E R + A S T R A L ---------------- 7 2 5 6 1 3

3 Answers   Honeywell,


Write a program to print fibonacci series without using recursion?

0 Answers  


Categories