you can call RealPerson::RealPerson anywhere, because it is public. same: you can call RealPerson::RealPerson anywhere, because it is public. static member function can visit non-static members, as long as it provide an object. you can visit non-static members anywhere, as long as you provide an object (and it is public, if you visit it from non-member). for ctor, you don't even need an object, because ctor create one.
【在 t****t 的大作中提到】 : : you can call RealPerson::RealPerson anywhere, because it is public. : same: you can call RealPerson::RealPerson anywhere, because it is public. : static member function can visit non-static members, as long as it provide : an object. you can visit non-static members anywhere, as long as you provide : an object (and it is public, if you visit it from non-member). : for ctor, you don't even need an object, because ctor create one.
【在 f******y 的大作中提到】 : Effective C++ is using tr1? Which version are you reading?
r*y
17 楼
I tried this but it is not working: class A{ static A * f(){A * p= new B(); return p;} }; class B: public A{ }; So what is the reason? Thanks.
provide
【在 t****t 的大作中提到】 : : you can call RealPerson::RealPerson anywhere, because it is public. : same: you can call RealPerson::RealPerson anywhere, because it is public. : static member function can visit non-static members, as long as it provide : an object. you can visit non-static members anywhere, as long as you provide : an object (and it is public, if you visit it from non-member). : for ctor, you don't even need an object, because ctor create one.
t*t
18 楼
declare first, use later. so put A::f() after B.
【在 r*******y 的大作中提到】 : I tried this but it is not working: : class A{ : static A * f(){A * p= new B(); return p;} : }; : class B: public A{ : }; : So what is the reason? Thanks. : : provide
r*y
19 楼
Thanks a lot.
【在 t****t 的大作中提到】 : declare first, use later. so put A::f() after B.