C++ help needed: singleton.hpp

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

C++ help needed: singleton.hpp

Klaus Spanderen-2
Hi

in ql/patterns/singleton.hpp

   68     template <class T>
   69     T& Singleton<T>::instance() {
   70         static std::map<Integer, boost::shared_ptr<T> > instances_;
   71         #if defined(QL_ENABLE_SESSIONS)
   72         Integer id = sessionId();
   73         #else
   74         Integer id = 0;
   75         #endif
   76         boost::shared_ptr<T>& instance = instances_[id];
   77         if (!instance)
   78             instance = boost::shared_ptr<T>(new T);
   79         return *instance;
   80     }

IMO this function should be declared as inline function to avoid linker
problem.

 69     inline T& Singleton<T>::instance() {

Background: I'd problems with this function when linking QL under Windows to a
project without including the QL project into my project (simply linked
static QL library).

any comment?

cheers
--
Klaus Spanderen
Ludwig Erhard Str. 12
48734 Reken (Germany)
E-Mail: [hidden email] (remove NOSPAM from the address)


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: C++ help needed: singleton.hpp

Luigi Ballabio
On Fri, 2007-09-21 at 21:24 +0200, Klaus Spanderen wrote:
> in ql/patterns/singleton.hpp
>
>    68     template <class T>
>    69     T& Singleton<T>::instance() {

> IMO this function should be declared as inline function to avoid linker
> problem.
>
>  69     inline T& Singleton<T>::instance() {
>
> Background: I'd problems with this function when linking QL under Windows to a
> project without including the QL project into my project (simply linked
> static QL library).

Klaus,
        I'm a bit afraid that declaring it inline might play badly with the
static map. What kind of linker problem did you have?

Luigi


--

This gubblick contains many nonsklarkish English flutzpahs, but the
overall pluggandisp can be glorked from context.
-- David Moser



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev