class testa {
public:
int n;
double s;
void funca();
void funcb();
};
void testa::funca() {
n = 500;
}
void testa::funcb() {
double s = 1.0/n;
cout << s << endl;
}
int main()
{
testa x;
x.funca();
x.funcb();
}
In function funcb() if I add type double before s, it doesn't work. Without the type name, it works. Could anyone tell me why? Double definition cannot work?
class testa {
public:
int n;
double s;
void funca();
void funcb();
};
void testa::funca() {
n = 500;
}
void testa::funcb() {
double s = 1.0/n;
}
int main()
{
testa x;
x.funca();
x.funcb();
cout << s << endl;
}
It surely won't work, right? How is it possible that double s = 1.0/n; could shadow the class variable s? They have the same name and void testa::funcb() is a member of the class. ?