Jump to content
  • Advertisement

Archived

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

rileyriley

declaring const config values within classes other than ints

This topic is 5415 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

I''m interested in saving some basic configuration info in my class. The problem is that the values I want to use are objects that need to be constructed. For example, say I wanted to store the default gravity as a Vector(0, 0, -9.8) and the default sound as a Sound("boing.wav"). What I *want* is to be able to put at the top of my Environment class something like:
class Environment
{
const Sound defaultSound = Sound("boing.wav");
const Vector gravity = Vector(0, 0, -9.8);

...
Obviously, that''s not legal. The closest thing I can come up with is:
class Environment
{
Sound defaultSound;
Vector gravity;

Environment()
{
defaultSound = Sound("boing.wav");
gravity = Vector(0, 0, -9.8);
}

...
I find the second way very cumbersome and unintuitive - and worst of all, I can''t make those values const. Does anyone see what I''m talking about, and know a way to get close to the desired effect? Thanks for any feedback~

Share this post


Link to post
Share on other sites
Advertisement

class Class {
Class(Type value1, Type value2) : constMember1(value1), constMember2(value2) {}
const Type constMember1;
const Type constMember2;
static const Type staticConstMember;
};

const Type Class::staticConstMember = value;



[edited by - eighty on November 28, 2003 1:58:05 AM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!