answersLogoWhite

0

Any values that are marked as 'public' as a class member are global, and therefore accessible to any code in a c++ program. Since this defeats encapsulation, it isn't a good idea. You want to have the class public members maintain control of what will be allowed for changing class data members, not arbitrary code.

User Avatar

Wiki User

∙ 16y ago
User Avatar

What else can I help you with?

Related Questions

How do you create a class in C plus plus?

class class_name { private: data_members; public: member_functions; };


What if you declare public members rather than private in c plus plus?

Public members in C++ have accessibility to any function that has scope to the instance of the class, whereas private members have accessibility only to functions of that class.


Do the memory will be created for both private and public data members if the object is created for a class in c plus plus?

Yes.


Demonstrate single inheritance in C plus plus?

struct base1 { // ... }; struct base2 { // ... }; struct derived1 : public base1 // single inheritance { // ... }; struct derived2 : public base1, public base2 // multiple inheritance { // ... };


Is there anything similar between C and C plus plus with reference to data hiding?

No. Data hiding is a feature of object oriented programming. C does not support OOP, and therefore has no private member access. All members are public in C.


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Why you use public mode in c plus plus?

To expose an interface to the class members. Without an interface of some kind, an object would be useless.


Symplify c plus c plus c plus c?

4c


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.


What is an instance class in C plus plus?

You have a class(i.g. MyClass): class MyClass{ public: int MyData; }; And then you use the class like this: int main(){ MyClass MyObject; MyObject.MyData=7; }