Furthermore, there are two ways to implement a member function:
1. Inside the class definition
1 2 3 4 5 6 7 8
|
class Example { // definition of Example starts here
void member()
{
// implementation of function 'member'
}
}; // definition of Example ends here
| |
2. Outside of class definition
1 2 3 4 5 6 7 8 9 10
|
class Example { // definition of Example starts here
void member(); // declaration of function
}; // definition of Example ends here
void Example::member()
{
// implementation of function 'member'
}
| |
The incomplete fragments of code that you have posted do not show whether you even attempt to do the right thing.
you can use getteri and or friend functions
error: C++ member is inaccessible |
The members that you try to access are
private to the class. Only members of class can access them.
A "getteri" is a member function.
The
operator<< cannot be a member function. It is a stand-alone function. It can call
public getteri member functions of the class.
You must have been explained what a "friend function" is. A stand-alone function that the class does
declare within its definition to be a friend. Friend has access to private members.
1 2 3 4 5 6 7 8 9 10
|
class Example { // definition of Example starts here
friend void nonmember(); // declaration of friend
}; // definition of Example ends here
void nonmember()
{
// implementation of function 'nonmember'
}
| |