Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

friend and this pointer help

Status
Not open for further replies.

ecannizzo

Programmer
Sep 19, 2000
213
US
Can someone tell me why intLeapInd and intDayOfYear isn't getting set? (I'll only post bits of code)

<code>
class DateObj
{
//private
int intMonth,
intDay,
intYear,
intLeapInd,
intDayOfYear;
friend void LeapYear(DateObj ob);
friend void DayOfYear(DateObj ob);

public:
DateObj(int m, int d, int y);
void Display();
};

DateObj::DateObj(int m, int d, int y)
{
intMonth = m;
intDay = d;
intYear = y;
LeapYear(*this);
DayOfYear(*this);
}

void LeapYear(DateObj ob)
{
//do calc to see if leap year

if ((ob.intYear % 4 == 0) && (ob.intYear % 100 != 0 || ob.intYear % 400 == 0))
ob.intLeapInd = 1; //this is a leap year
else
ob.intLeapInd = 0; //this is not a leap year

}
</code>

Thanks!
 
try passing the argument by reference

the function declaration would be:
friend void LeapYear(DateObj& ob);

and it's implementation would become:
void LeapYear(DateObj& ob)
{
//keep the same code
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top