I am having a problem accessing a static const variable defined in my class private member variable section. Specifically, the code written below can output the variable within the constructor, but when I try to access it through an accessor function, I get an error discussed below. If anyone knows why I would appreciate your help.
#include <iostream>
using namespace std;
class TestStaticVariables
{
// Private member variable:
static const double static_double_variable;
public:
// Constructor:
TestStaticVariables()
{
// Initialization:
static const double static_double_variable = 20.0;
cout << static_double_variable;
}
// Member Function:
void test();
};
void TestStaticVariables::test()
{
When this next line is uncommented I get the following error message:
Line Location Tool:0: "TestStaticVariables::static_double_variable", referenced from:
//cout << static_double_variable;
}
int main(int argc, char* const argv[])
{
TestStaticVariables test_instance;
return 0;
}