answersLogoWhite

0


Best Answer

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

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which C plus plus keyword allows a function outside of a class to access private class members?
Write your answer...
Submit
Still have questions?
magnify glass
imp
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.


What keyword in class specification helps you to hide data?

private


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 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 limitations of friend function in c plus plus?

Only that they cannot be inherited by derived classes. This is "a good thing". Other than that, a friend function has full access to a class' private and protected members and you cannot limit its scope. At this data hiding feature of c++ is broken.

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.


What keyword in class specification helps you to hide data?

private


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.


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 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


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 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.


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.


When class will be used and when structure will be used?

In class default members are private and in structure default members are public ,When ever you want to hide data from outside functions then you can use class.But in ANSI C we can hide data by using private access specifier.