Storing static class members of dynamic variable type in a dll

I need to do this but can't figure out how I can implement it.

Tickable.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <list>

#ifdef TICKABLE_EXPORTS //Automatically defined by MSVS
#define DLL __declspec(dllexport)
#else
#define DLL __declspec(dllimport)
#pragma comment(lib, "Tickable.lib")
#endif

class DLL Tickable{
public:
    Tickable() //cpp defines to add 'this' pointer to 'subs'
    ~Tickable() //cpp defines to remove this instance from 'subs'
    virtual void Tick(double seconds); //just returns... designed for polymorphism
    void static TickAll(double seconds); //runs Tick(double seconds) for all members of 'subs'
private:
    static std::list<Ticakble*> subs; //ERROR!
}


error LNK2001:
unresolved external symbol "private: static class std::list<class Tickable*,SKIPPED BITS> Tickable::subs" HUGE_SYMBOL_LIST
PATH\Tickable.obj


I know with such a tiny and insignificant class the dll export seems pointless but this class is actually intended to be a .lib ONLY. But it is derived from by .dll style classes, and through inheritance this error is the exact same as what appears in the derived class, I just imagine that the cut down version would be easier to work with.

EDIT: Sorry, forgot to actually state the question (silly me)...
Is it possible to hold either a static variable in a dll which is of a dynamic type, OR would it be possible to reference an external variable which is static throughout the instances and this variable can be chucked away in a namespace of mine somewhere?
I suppose my only other option (if this is possible) would be to define a maximum instance number and create a standard array of pointers but this could both waste so much memory when not in use and cause problems if I need more memory.
Last edited on
*bump* Sorry for being inpatient but my project sort of comes to a complete stop until I can fix this :(
About the linker error, ┬┐have you defined the instance in a cpp?
std::list<Tickable*> Tickable::subs;
Don't quite understand how you mean.

Tickable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "Tickable.h"

Tickable::Tickable(){
    subs.push_back(this);
}
Tickable::~Tickable(){
    std::list<Tickable*>::iterator iter = subs.begin();
    for(; iter != subs.end(); iter++){
        if(*iter == this){
            subs.erase(iter);
            return;
        }
    }
}
void Tickable::Tick(double seconds){
    return;
}
void SB::Tickable::TickAll(double seconds){
    std::list<Tickable*>::const_iterator iter = subs.cbegin();
    for(; iter != subs.cend(); iter++){
        (*iter)->Tick(seconds);
    }
}


This is the entire CPP file
Last edited on
line 17 of Tickable.h is a declaration. You are simply saying that variable exists.
But you never create it.

Put in your Tickable.cpp
std::list<Tickable*> Tickable::subs;
THANK YOOOUUSS...
Just to clarify, now that the variable has been defined once (and I assume because the class is exported to DLL or LIB that the object is packed there), that even without this cpp file now, I'll be able to inherit from this class with no problems?
Topic archived. No new replies allowed.