"Gactimus" <gactimus@xrs.net> wrote in message news:1101261553.GjujyReqCwFEwAYYiUSFRA@bubbanews.. .[color=blue]
> Hey again,[/color]
Yo.
[color=blue]
> I am working my way through the book "C++ Primer Fourth Edition".
>
> I am trying to run a program out of the book using Microsoft Visual C++
> version 6 and I am given the error message:
>
> : error C2248: 'hours' : cannot access private member declared in class 'Time'
> : error C2248: 'minutes' : cannot access private member declared in class 'Time'
>
> Here is the code. I have indicated where the compiler says the problem lies:[/color]
I've trimmed it severely. Please note my code insertion below.
[color=blue]
> #include <iostream>
> using namespace std;[/color]
class Time;
ostream & operator<<(ostream & os, const Time & t);
[color=blue]
> class Time
> {
> private:
> int hours;
> int minutes;
> public:
> Time();
> Time(int h, int m = 0);
> void AddMin(int m);
> void AddHr(int h);
> void Reset(int h = 0, int m = 0);
> Time operator+(const Time & t) const;
> Time operator-(const Time & t) const;
> Time operator*(double n) const;
> friend Time operator*(double m, const Time & t)
> {return t * m;}
> friend ostream & operator<<(ostream & os, const Time & t);
> };
> Please help!!![/color]
Your code compiles fine with a less buggy compiler.
Your difficulty is due to a (somewhat) well known bug
in MSVC6. If you insert the code I did above, the
function being declared as a friend will exist enough
in the symbol table to be befriendable and treated
properly later.
--
--Larry Brasfield
email:
donotspam_larry_brasfield@hotmail.com
Above views may belong only to me.