Serene
08-15-2002, 09:18 PM
#include <iostream.h>
class Student
{
public:
static int noOfStudents;
Student &nextStudent()
{
noOfStudents++;
return *this;
}
};
int Student::noOfStudents;
void fn(Student &s)
{
cout<<s.nextStudent().noOfStudents<<endl;
}
void main()
{
Student ss;
cout<<(ss.noOfStudents)<<endl;
fn(ss);
(Student::noOfStudents)=+18;
clog<<Student::noOfStudents<<endl;
}
I have compiled it and ran it when I called "s.nextStudent().noOfStudents" the noOfStudent return value is 1.if not value is 0,this is okay.but when "(Student::noOfStudent)=+18,the value is 18,(I thought should be 19),I remark it with //(St......),the output is 1.I could understand why? Static vary changed its value ,the value will be changed and kept.so 1+18 should be 19.
class Student
{
public:
static int noOfStudents;
Student &nextStudent()
{
noOfStudents++;
return *this;
}
};
int Student::noOfStudents;
void fn(Student &s)
{
cout<<s.nextStudent().noOfStudents<<endl;
}
void main()
{
Student ss;
cout<<(ss.noOfStudents)<<endl;
fn(ss);
(Student::noOfStudents)=+18;
clog<<Student::noOfStudents<<endl;
}
I have compiled it and ran it when I called "s.nextStudent().noOfStudents" the noOfStudent return value is 1.if not value is 0,this is okay.but when "(Student::noOfStudent)=+18,the value is 18,(I thought should be 19),I remark it with //(St......),the output is 1.I could understand why? Static vary changed its value ,the value will be changed and kept.so 1+18 should be 19.