hi,
The following code just doesn;t work even though it is correct. It gives an error can't access mo even though the it is accessed within the friend function. Try it!. Please let me know what's worng.
#include <iostream>
using namespace std;
class Date
{
int mo, da, yr;
public:
Date( int m, int d, int y )
{
mo = m; da = d; yr = y;
}
friend ostream& operator<< ( ostream& os, Date& dt );
};
friend ostream& operator<< ( ostream& os, Date& dt )
{
os << dt.mo << '/' << dt.da << '/' << dt.yr;
return os;
}
void main( )
{
Date dt( 5, 6, 92 );
cout << dt;
}
The following code just doesn;t work even though it is correct. It gives an error can't access mo even though the it is accessed within the friend function. Try it!. Please let me know what's worng.
#include <iostream>
using namespace std;
class Date
{
int mo, da, yr;
public:
Date( int m, int d, int y )
{
mo = m; da = d; yr = y;
}
friend ostream& operator<< ( ostream& os, Date& dt );
};
friend ostream& operator<< ( ostream& os, Date& dt )
{
os << dt.mo << '/' << dt.da << '/' << dt.yr;
return os;
}
void main( )
{
Date dt( 5, 6, 92 );
cout << dt;
}