I was trying to initialize a static member of a class with another class's static member. But I guess because of some 'undefined' reasons, when the initialization happening, initializer was not yet instantiated. So that the data was not copying because of order of instantiation.
Here it is how it looks like,
/* class1.h */
#include "class2.h"
class class1 {
public:
static const int x;
static int init()
{
return class2::y;
}
};
/* class1.cpp */
const int class::x = class1::init();
/* class2.h */
struct class2 {
static const int y;
};
/* class2.cpp */
const int class2::y = 5;
It was a rough definition of my purpose. As you can see, I am trying to initialize a static data member of class1 with a function call which returns another class's static data member. As I expect that, instead of class1's data member initialized with the function call, it just 'value-initialized'.
As I guess it is happening because of there is no any specification for the order of static type variable execution.
Is there a way to over it?
Thank you
Aucun commentaire:
Enregistrer un commentaire