Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.

0 Answers  


how should functions be apportioned among source files?

0 Answers  


How arrays can be passed to a user defined function

0 Answers  


What are the header files used in c language?

0 Answers  


What is the best way of making my program efficient?

0 Answers  


What compilation do?

7 Answers   Geometric Software, Infosys,


Q. where is the below variables stored ? - volatile, static, register

3 Answers   Bosch,


How to compare array with pointer in c?

0 Answers  


What are the types of arrays in c?

0 Answers  


Can u return two values using return keyword? If yes, how? If no, why?

7 Answers  


What is the purpose of Scanf Print, getchar, putchar, function?

3 Answers  


What does %c mean in c?

0 Answers  


Categories