Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

EvilCrap

Is this standard c++ ?

This topic is 5189 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

for you c++ gurus, could u clarify this for me? On the .net compiler, a static base class member is shared by derived classes, but if i recall, on the mvc6 compiler, derived classes had their own instance of static variables. which is standard? for instance:
class CBase{
public:
static int i;
};
int CBase::i=0;
class CDerA: public CBase{
public:
 void p(){ cout << i++;}
};
class CDerB: public CBase{
public:
 void p(){ cout << i++;}
};
void main(){
 CDerA a;
 a.p(); a.p();
 CDerB b;
 b.p();
}
on .net compiler result is "012" is this an unstandard behavior i should avoid or is it proper?

Share this post


Link to post
Share on other sites
Advertisement
A static variable in a base class won''t be reinstantiated in derived classes. They''ll all refer to the base class. This was also the case in MSVC6, IIRC.


"Sneftel is correct, if rather vulgar." --Flarelocke

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!