"
Employee::employeeNumber" is private. In general, private data-members cannot be read from or written to by a function or class that's neither a friend class, friend function or member-function.
You have a few choices to overcome this problem:
1)
Friends. A
friend of a class is either a function or another class that's allowed to read or write to private data-members directly. Here's an example:
1 2 3 4 5 6 7 8 9 10 11 12
|
class Something
{
int X;
public:
friend int ReadXFromSomething( Something &Object );
};
int ReadXFromSomething( Something &Object )
{
return( Object.X );
}
| |
Here, "
ReadXFromSomething( )" is a friend of "
Something" and is allowed direct access to the data-members of another "
Something" object.
2)
Getters. Getters are the counterpart of
setters. Getters obtain the value of a data-member. It's common practice (and preferred) for getters member-functions to return either a non-constant copy or a constant reference to some data-member.
1 2 3 4 5 6 7 8 9 10 11
|
class Something
{
private:
int X;
public:
int GetXCopy( ) const
{
return( X );
}
};
| |
Here, "
Something::GetXCopy( )" is a getter. Note the "
const" qualifier; it's used to tell the compiler that the data-members will not be modified during the call to "
Something::GetXCopy( )". It's common for getters to be declared this way.
Both of the above solutions respect the encapsulation concept when applied correctly. Please, in the future,
avoid setters at all costs.
Wazzak