Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ behaviour when const

Tags:

c++

Here's a basic struct (I hope)

struct SomeType {
    float a;
    float b;
    float c;
    float d;

    SomeType(float, float, float, float);
};

And source

SomeType::SomeType(float na, float nb, float nc, float nd) : a(na), b(nb), c(nc), d(nd) {}

The I have a class

struct SomeClass {
    static const SomeType v;

    SomeClass();
};

When I then initialise it

const SomeType SomeClass::v(0,0,0,0);

My vales become inf or nan or -nan. Anyone seen this before, or know how to fix it?

Edit: Fixed type

Edit: This is quite close to my original example. I multiple classes with similar structure to SomeClass.

like image 352
NebulaFox Avatar asked Feb 26 '23 17:02

NebulaFox


1 Answers

const SomeClass::v(0,0,0,0);

won't compile, since you didn't specify the type of v.

Otherwise, this works for me (and should work).

Perhaps you should post a complete, compilable example in one code listing, so we can see what you really had in mind.

like image 158
Alex Budovski Avatar answered Mar 08 '23 04:03

Alex Budovski