static class member initialization

Discussion in 'C++' started by Philipp Kraus, Dec 18, 2012.

  1. Hello,

    I have got a problem with the initialization of a static class member
    of a singleton class.
    The class shows (short) :

    class myPluginUse {

    public :

    template<typename T> T myMethod();

    private :

    static myPluginUse* m_instance;

    }


    This class is used in the main program and I initialialize the static
    member on the before the
    main function. This works well, but this class is also used in a plugin
    (DLL) but at the moment
    I need a initialization of the static member also on the plugin, which
    includes this header.
    But the plugin cpp file needs only the public part of the class, not
    the private or static member
    or any implementation. I can "copy" the header part, but I don't want
    to use two different files.

    How can I use "one" header without a static initialization on my plugin
    cpp and initialization on
    my main program?

    Thanks

    Phil
     
    Philipp Kraus, Dec 18, 2012
    #1
    1. Advertising

  2. On 12/18/2012 2:49 PM, Philipp Kraus wrote:
    > I have got a problem with the initialization of a static class member of
    > a singleton class.
    > The class shows (short) :
    >
    > class myPluginUse {
    >
    > public :
    >
    > template<typename T> T myMethod();
    >
    > private :
    >
    > static myPluginUse* m_instance;
    >
    > }
    >
    >
    > This class is used in the main program and I initialialize the static
    > member on the before the
    > main function. This works well, but this class is also used in a plugin
    > (DLL) but at the moment
    > I need a initialization of the static member also on the plugin, which
    > includes this header.


    Huh? Two buts in a sentence - I am confused.

    > But the plugin cpp file needs only the public part of the class, not the
    > private or static member
    > or any implementation. I can "copy" the header part, but I don't want to
    > use two different files.
    >
    > How can I use "one" header without a static initialization on my plugin
    > cpp and initialization on
    > my main program?


    Maybe...

    // part for use in the DLL
    class myPluginForDLLUse
    {
    public:
    virtual void foo() = 0; // interface
    };
    myPluginForDLLUse* someStandAloneFunction();

    // part for use in your implementation, along with the other part
    class myPluginImplementation : public myPluginForDLLUse
    {
    virtual void foo(); // this is where your functionality is

    // and all other stuff that your plugin needs at creation
    };
    // implemenation of your stand-alone function
    myPluginForDLLUse* someStandAloneFunction()
    {
    static myPluginImplementation myPlugin;
    return &myPlugin;
    }

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Dec 19, 2012
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Klatt
    Replies:
    6
    Views:
    2,706
    Jesper Madsen
    Nov 18, 2003
  2. Siemel Naran
    Replies:
    4
    Views:
    815
    Micah Cowan
    Jan 12, 2005
  3. , India
    Replies:
    2
    Views:
    399
    Tadeusz B. Kopec
    Nov 13, 2007
  4. dolphin
    Replies:
    3
    Views:
    1,362
    Pete Becker
    Dec 5, 2007
  5. Replies:
    23
    Views:
    882
    James Kanze
    Jun 15, 2008
Loading...

Share This Page