After a bit more experimentation I can come up with the following.
A simple singelton works. That is good.
What I am trying to implement though is a factory setup along these
lines:
/**
* Humans are quite simple
*/
class IHuman {
public:
virtual string sayHello() = 0;
};
/**
* is an abstract base class
* which provides a static lookup factory function
* and a map which will contain factories for different
* kind of humans.
*/
class HumanFactory {
public:
static IHuman * createHuman(string const & type, string const &
name)
{
map<string, HumanFactory*>::iterator iter =
s_factories.find(type);
if(iter != s_factories.end())
return iter->second->createHuman(name);
else
return 0;
}
protected:
virtual IHuman * createHuman(string const & name) = 0;
HumanFactory() {;}
HumanFactory(string const & type, HumanFactory * factory)
{ s_factories[type] = factory; }
private:
static map<string, HumanFactory *> s_factories;
};
/**
* A Male is a Human.
* It can only be created using a HumanFactory.
* The Factory part registers itself within the constructor()
* with the HumanFactory. The static createHuman method
* uses the createHuman Method of the class to create a Male person
*/
class Male : public IHuman, public HumanFactory {
public:
virtual string sayHello();
protected:
virtual IHuman * createHuman(string const & name)
{return new Male(name);}
private:
string m_name;
Male() : HumanFactory("male",this) {}
Male(string const & name) : m_name(name) {}
static Male s_registerMe;
};
This never works using libtool. However just doing "c++ `find . -name
*.cpp`"
does the trick.
Any glue what is going on?
Michael Matz wrote:
>
> Hi,
>
> On Fri, 25 Aug 2000 [EMAIL PROTECTED] wrote:
> > has anyone managed to get static constructors working using the libtool
> > ml-branch and automake (1.4) and would be able to give me some hints? I
> > am woking on linux, with gcc2.95.2.
>
> We use the ML-branch for KDE, and our libs use static objects, so we have
> that working. What exactly are your problems? Note, that in connection
> with dlopen() and especially dlclose() static objects have may issues
> (e.g. all crashes right away, when there is a static object local to a
> function, they all must be in the file scope; there are more serious
> failures with dlclose). But normal shared libs loaded on application start
> should just work.
>
> Ciao,
> Michael.
--
·´¯`·.¸¸..><((((º>.·´¯`·.¸¸.·´¯`·.¸><((((º>¸.·´¯`·.¸.,..·´¯`·..
><((((º>`·.¸¸.·´¯`·.¸.·´¯`·...¸><((((º> [EMAIL PROTECTED]