Archived

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

Kyo

Accessing a static object's function within the class's function gives error

Recommended Posts

I have a class, CSound, within another class CBomb. A CSound class is associated with a wav file and since every CBombs will use the same explosion.wav I need to make CSound static. It''s something like this: class CBomb { public: ... private: static CSound explosion; }; CBomb::aFunction() { explosion.playSound(); } this gives me: unresolved external symbol "private: static class CSound CBomb::sndExplosion" It won''t let me call playSound from a function of CBomb. Any idea why? And is there an easy way of loading the CSound explosion within the init member function of CBomb but making sure it''s only initialized once (i''m trying to use a static bool flag for that at the moment) thanks.

Share this post


Link to post
Share on other sites
If you are talking about declaring the static class variable, that''s the only way. If you''re talking about static variables in general, I don''t think you''re doing it the wrong way at all. Static class variables are used when you want all instances of a class to share the same variable (literally) while maintaining class access rights. That looks exactly like what you''re doing.

Share this post


Link to post
Share on other sites