Reputation: 15668
I'm not able to reprdouce the problem I have in my target application in some a nice & compact form to display, but I have written up the class definition I'm using for mysingleton that's causing me grief and I hope someone may be able to direct me to the solution.
Ok, the problem is, my application returns a runtime error that goes like:
Error opening requested library (/path/to/./libcloudparc.sys.db_connector.so) dlopen() error: /path/to/./libcloudparc.sys.db_connector.so: undefined symbol: _ZN7db_pool8instance
where db_pool
is my singleton class that looks like:
class someclA {
public:
someclA(int,int,int){}
~someclA(){}
};
class db_pool : public someclA {
private:
static db_pool *inst;
db_pool(int &A,
int &B,
int &C): someclA(A,B,C){}
public:
static db_pool *getInstance(int &a,
int &b,
int &c) {
if(!inst) {
inst = new db_pool(a,b,c);
inst->init(a,b,c);
}
return inst;
}
int init (int ,int,int);
};
int main (void) {
int A=11;
int B=22;
int C=33;
db_pool *inst = inst->getInstance(A,B,C);
}
Why would I get a error as mentioned? Can anybody help me get ahead here?
Upvotes: 0
Views: 164
Reputation: 26800
If a variable in a class is static
, it would belong to all instances of that class and not to one instance alone. So it would need to defined first.
And you can have only one definition of that variable. So it has to be put in a source (not header) file outside of the class declaration. You need to do something like this:
db_pool * db_pool::inst = nullptr; //for a start
Upvotes: 1