Originally Posted by
iMalc
Wow, 16 hours have passed, and nobody has corrected the above posted. Heck, there's even a "like" on it!
I did not bother checking since I vaguely recalled something about this kind of disambiguation being used similiar to what antred mentioned.
Originally Posted by
iMalc
No, they are not the same.
Because of the caveat "in this case", antred does not appear to dispute that.
EDIT:
Originally Posted by
iMalc
Person::name refers to a static class member. Being static means that there is only one name in the entire program. Every Person object would be associated with the name "Bob" for example. (...) You cannot use the two interchangably.
g++ 4.6.3 and the Comeau online compiler compile this test program without any warnings:
Code:
#include <iostream>
class X
{
public:
X() : n(1) {}
virtual ~X() {}
virtual void foo() const
{
std::cout << n << std::endl;
}
protected:
int n;
};
class Y : public X
{
public:
Y() : n(2) {}
void setN(int n)
{
Y::n = n;
}
virtual void foo() const
{
std::cout << X::n << ',' << Y::n << std::endl;
}
private:
int n;
};
int main()
{
Y y;
y.foo();
y.setN(3);
y.foo();
}
When run after being compiled by g++ 4.6.3, the output is:
EDIT #2:
Oh, but of course, one oft-cited case of the use of this is when a name foo in a derived class D hides members of the same name in the base class B. A using declaration like using B::foo; in the definition of D would then be appropriate, even if the members named foo in the base class are non-static.