Hello!
In my class, I created an ostream/istream friend member.
And when I try to get to private files it's not letting me... why?
Thanks!!
Clock.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class Clock
{
int houre;
int minute;
int second;
public:
Clock();
Clock(int, int, int);
Clock(const Clock & clock);
...
void operator+=(int);
friend ostream& operator<<(ostream&, const Clock&);
friend istream& operator>>(istream&, const Clock&);
};
|
Clock.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include "Clock.h"
Clock::Clock()
{
houre = 00;
minute = 00;
second = 00;
}
...
ostream & operator<<(ostream& out, Clock & myClock)
{
//myClock.houre
}
istream & operator>>(istream & in, Clock & myClock)
{
}
|
Last edited on
Your declaration and your implementation have different signatures. i.e. const
is missing on the implementations.
Because the signatures are different, the compiler does not recognize the implementations as friends.
BTW, you DON'T want const
on your >> operator, since you want to store the result in the passed instance.
Last edited on