M
Michael Klatt
I am working on a library which uses the GKS graphics package. I have
a Gks object which opens the GKS subsystem in its constructor:
// Gks.hpp
class Gks
{
public :
Gks();
};
--------------------
// Gks.cpp
#include "Gks.hpp"
Gks::Gks()
{
// open GKS subsystem
}
I have several types of object which need the GKS subsystem to be
opened before they can be created. I need something like a global
static Gks object, but since this is tricky to do in a library I'm
trying a solution that uses inheritence. All classes which need a
static Gks object derive from GksInit:
// GksInit.hpp
#include "Gks.hpp"
class GksInit
{
public :
virtual ~GksInit() {}
protected :
GksInit();
private :
static const Gks ourGks;
};
--------------------------
//GksInit.cpp
#include "GksInit.hpp"
const Gks GksInit:urGks; // make sure GKS gets initialized
GksInit::GksInit() {}
----------------
// Workstation.hpp
// GKS needs to be initialized before a Workstation can be created
#include "GksInit.hpp"
class Workstation : public GksInit
{
...
};
This all seems to work as desired, but here is my problem/question.
If I inline the GksInit constructor in the header file, the
GksInit:urGks static member never gets constructed. Why is this?
a Gks object which opens the GKS subsystem in its constructor:
// Gks.hpp
class Gks
{
public :
Gks();
};
--------------------
// Gks.cpp
#include "Gks.hpp"
Gks::Gks()
{
// open GKS subsystem
}
I have several types of object which need the GKS subsystem to be
opened before they can be created. I need something like a global
static Gks object, but since this is tricky to do in a library I'm
trying a solution that uses inheritence. All classes which need a
static Gks object derive from GksInit:
// GksInit.hpp
#include "Gks.hpp"
class GksInit
{
public :
virtual ~GksInit() {}
protected :
GksInit();
private :
static const Gks ourGks;
};
--------------------------
//GksInit.cpp
#include "GksInit.hpp"
const Gks GksInit:urGks; // make sure GKS gets initialized
GksInit::GksInit() {}
----------------
// Workstation.hpp
// GKS needs to be initialized before a Workstation can be created
#include "GksInit.hpp"
class Workstation : public GksInit
{
...
};
This all seems to work as desired, but here is my problem/question.
If I inline the GksInit constructor in the header file, the
GksInit:urGks static member never gets constructed. Why is this?