Member Avatar for Thew

Hello,
I'm trying to use some default (static) members for my class. At first I've created class which looks like this (this is just a small code):

//rozšírenie materiálu, M (par (ext))
typedef struct ExtendedMaterial
{
    //hmotnosť
    float Substantiality;
    //krehkosť - tuhé látky, viskozita - tekuté látky
    float Insubstantiality;
    //hustota
    float Consistence;
} ExtendedMaterial;

class Physics
{
public:
    //need to add some static members here
    Physics();
    ~Physics();
    ...
private:
    ...
};

I've tried something like this:

static ExtendedMaterial DefaultExtMat = {1.0f,0.0f,1.0f};
    static Vector3 DefaultVector(0,0,0);

but everytime I try this I get an error like this one:
error C2334: unexpected token(s) preceding '{'; skipping apparent function body
error C2059: syntax error : 'constant' //for static Vector3 DefaultVector(0,0,0);

Should I create static function that will return the default values, or any other, way, just to use something like: Physics::DefaultExtMat

Recommended Answers

All 2 Replies

hi,
static member must be initialized outside of class declaration, for example below }; of class def:

class C
{
   public:
      static int st;
   ...
};

int C::st = 2008; // must be outside class declaration

krs,
tesu

Member Avatar for Thew

Really thank you :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.