I'm having a strange issue where I'm unable to modify one of the static members of a class after initializing the class. Here's the code I have:
my_values.hpp
#include "weird_class.hpp"
namespace foo {
class Bar {
public:
static WeirdClass weird_class_obj;
};
my_values.cpp
#include "weird_class.hpp"
#include "my_values.hpp"
namespace foo {
WeirdClass Bar::weird_class_obj = WeirdClass(1.0f, 0.0f, 1.0f, 100.0f);
Bar::weird_class_obj.set_weird_value(100.0f);
}
weird_class.hpp
#ifndef WEIRD_CLASS_H
#define WEIRD_CLASS_H
class WeirdClass {
public:
WeirdClass(float, float, float, float);
void set_weird_value(float);
private:
float weird_value;
};
#endif
weird_class.cpp
#include "weird_class.hpp"
void WeirdClass::set_weird_value(float weirdValue) {
weird_value = weirdValue;
}
If I comment out line 5 in my_values.cpp
the files compile fine. But if I don't, the error I get is
error: no type named 'weird_class_obj' in 'foo::Bar' Bar::weird_class_obj.set_weird_value(100.0f);
^
error: cannot use dot operator on a type Bar::weird_class_obj.set_weird_value(100.0f);
^
My guess is that weird_class_obj
is somehow being treated as a type rather than an object of class WeirdClass
. But why would this be?