I want to create a class that collects information from many other classes and the end of a simulation. For that, it has to be independent from all other classes and completely accessible. For that I chose a static approach, a static struct indeed.
This is my Foo.h
class Foo
{
public:
static int app_counter;
typedef struct
{
double eed;
int bits;
}APPLayer;
static APPLayer applayer_metric;
public:
Foo(){};
~Foo();
};
This is the Foo.cpp
#include "Foo.h"
int Foo::app_counter=0;
//How do I set all internal members to zero?
Foo::APPLayer applayer_metric;
Foo::~Foo()
{
std::cout << app_counter << std::endl;
//Which is the way to access to the values of my members?
std::cout << applayer_metric.bits << std::endl;
}
This is the error I get in my Foo.CPP
Foo.cc:38: undefined reference to `Foo::applayer_metric'
If for instance I change the line in Foo.cpp to this one
std::cout << Foo::applayer_metric.bits << std::endl;
I get exactly the same error.
My questions are:
- How can I initialize all members of a static struct variable to zero?
- How do I access to these members in other functions in Foo.cpp?
FYI, there is no complain if I initialize and access the variable "app_counter"
What am I doing wrong?
Thanks in advance.