Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Friend keyword:
- Lets a function acces members from a class,
- Example:
- #include <iostream>
- using namespace std;
- class FelixClass
- {
- public:
- FelixClass()
- {
- regVar = 0;
- }
- private:
- int regVar;
- friend void printCrap(FelixClass &felixobject);
- };
- void printCrap(FelixClass &felixobject)
- {
- felixobject.regVar = 99;
- cout << felixobject.regVar << endl;
- }
- int main()
- {
- FelixClass felixobject2;
- printCrap(felixobject2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement