answersLogoWhite

0

The keyword is friend. The external function must be declared a friend of the class (from within the class itself) in order to become a member of the class and thus gain access to the private (and protected) members of the class.

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

What is the purpose of the keyword private?

The private keyword is used to ensure that no other classes will be able to access (view or modify) that class member.


How can you access private functions of a class from the Main function in Cpp?

Any member functions and data members declared as 'private' in a class, can only be accessed directly by functions within the class.They cannot be accessed directly by derived objects, nor from anywhere outside an object of the class, such as from the Main function.To access private class members, you must rely on what are called accessor functions. Accessor functions are functions inside the class, either public or protected, which automatically have access to private members.If a function from Main, or elsewhere outside the class hierarchy, needs access, then you need to use publicaccessor functions. For derived class access, you can use protected accessor functions.


What keyword in class specification helps you to hide data?

private


What is public in c plus plus?

public is an access-modifier that allows you to access methods or properties of a class from outside of the class. A method or property set to protected can only be accessed from within the creating class or subclasses, while a private method or property can only be accessed from within that class


When should a member of a class be declared public?

When the member needs to be accessible from outside of the class. Private members are only accessible from within the class itself, including friends of the class. Protected members are the same as private members but are also accessible to derived classes. Derived classes therefore inherit both the protected and public members of its base classes.

Related Questions

What is the purpose of the keyword private?

The private keyword is used to ensure that no other classes will be able to access (view or modify) that class member.


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.


Is it possible to access the private variable in CPP from outside the class?

Private variables can only be accessed from outside of a class by using any public function of that same class. Or this can be accomplished by using Friend functions.


How can you access private functions of a class from the Main function in Cpp?

Any member functions and data members declared as 'private' in a class, can only be accessed directly by functions within the class.They cannot be accessed directly by derived objects, nor from anywhere outside an object of the class, such as from the Main function.To access private class members, you must rely on what are called accessor functions. Accessor functions are functions inside the class, either public or protected, which automatically have access to private members.If a function from Main, or elsewhere outside the class hierarchy, needs access, then you need to use publicaccessor functions. For derived class access, you can use protected accessor functions.


How can I find reputable dealerships or private sellers that offer keyword?

To find reputable dealerships or private sellers that offer keyword, you can start by researching online reviews, checking with consumer protection agencies, and asking for recommendations from friends or family members who have purchased similar items. Additionally, you can visit websites that specialize in listing trusted sellers or dealerships in your area.


Can you implement a constructor in private part of code?

no we cannot initialize a constructor in private in order to call a constructor from outside of a class it must be a public member.in order to create an object we should call the constructor .so only private members can implement outside of the class.


What keyword in class specification helps you to hide data?

private


What does a private loan agreement l?

A private loan agreement is a agreement between 2 people that is not publicly filed with any outside agency. Most private loan agreements are between family members.


What is public in c plus plus?

public is an access-modifier that allows you to access methods or properties of a class from outside of the class. A method or property set to protected can only be accessed from within the creating class or subclasses, while a private method or property can only be accessed from within that class


What are the difference between public and private inheritance in c plus plus?

Public member, fields, methods etc can be accessed from outside of the class. While private members etc can accessed only within the class even "child" classes do not have access to private members, fields etc.


If you want to guarantee that the object remains the same after calling a member function on it how would you declare the function?

You would place the const keyword before the function body: class Object { public: Object():m_num(1){} int GetData() const; private: int m_num; }; int Object::GetData() const { return(m_num); } Since GetData() does not alter the instance, it makes sense to declare the function as constant. Note that class instance data members that are declared mutable can still be altered, regardless of constant functions. The use of constant functions only guarantees the non-mutable members cannot be altered.


What is public access?

In a class definition, the keyword "public:" denotes that all the following members (both variables and methods) are accessible to all consumers of the class. The access specifier remains in force until another access specifier is encountered, however the same specifier may be repeated throughout the definition, and they may appear in any order. Note that a class always has full access to all of its own members, regardless of the access specifiers. However, class members may be public, protected or private. This determines how accessible those members are to the consumers of the class. In other words, they determine how much of the interface you expose outside of the class. Unless otherwise specified, all class members are private. Private members are only accessible to the class itself, and friends of the class (whether those friends are entire classes, individual class methods, or individual functions). Protected members are similar to private members, but are also accessible to derived classes. Public members are accessible to all consumers of the class.