Click here to Skip to main content
15,915,763 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: WinNT to WinCE Pin
Tim Smith1-Aug-02 2:09
Tim Smith1-Aug-02 2:09 
GeneralLinking C API to C++ Virtual Functions. Pin
Jawache1-Aug-02 1:50
Jawache1-Aug-02 1:50 
GeneralRe: Linking C API to C++ Virtual Functions. Pin
Funky Chicken1-Aug-02 2:21
sussFunky Chicken1-Aug-02 2:21 
GeneralRe: Linking C API to C++ Virtual Functions. Pin
Jawache1-Aug-02 2:42
Jawache1-Aug-02 2:42 
GeneralRe: Linking C API to C++ Virtual Functions. Pin
Daniel Lohmann1-Aug-02 4:03
Daniel Lohmann1-Aug-02 4:03 
GeneralRe: Linking C API to C++ Virtual Functions. Pin
Jawache1-Aug-02 5:18
Jawache1-Aug-02 5:18 
GeneralRe: Linking C API to C++ Virtual Functions. Pin
Joaquín M López Muñoz1-Aug-02 7:15
Joaquín M López Muñoz1-Aug-02 7:15 
GeneralRe: Linking C API to C++ Virtual Functions. Pin
Daniel Lohmann1-Aug-02 8:13
Daniel Lohmann1-Aug-02 8:13 
Sounds to be a classical instantiation of the Singleton pattern. Therefore your approach with the static function to retrieve the one and only instance is quite fine. To make sure that there is never (even accidentally) another instance, you should declare the constructor as protected. The following shows the principle:
class Base
{
public:
    static Base& Instance()
    {
        ASSERT( Base::pInstance );
        return *Base::pInstance;
    }

    virtual void f(); 
    virtual void g();
    ...

protected:

    Base()
    {
        ...
    }
    
    // We don't need to implement this. Objects of class Base
    // are never copied. We just declare it to make sure, the
    // compiler does not produce one its own.
    Base( const Base& );

    static Base* pInstance;
};

class Derived : public Base
{
public:

     virtual void f();
     ...

    static void CreateTheInstance()
    {
        ASSERT( Base::pInstance == 0 );
        Base::pInstance = new Derived();
    }

protected:
    Derived()
    {
        ...
    }
};



During initialization or at some other appropriate point in time you have to call Derived::CreateTheInstance() to construct the one and only instance, that is afterwards accessable via Base::Instance().
Roll eyes | :rolleyes:

--

Daniel Lohmann

http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there Big Grin | :-D )
GeneralRe: Linking C API to C++ Virtual Functions. Pin
Jawache1-Aug-02 12:26
Jawache1-Aug-02 12:26 
QuestionRandomic functions ? Pin
Cris1-Aug-02 1:47
Cris1-Aug-02 1:47 
AnswerRe: Randomic functions ? Pin
Nish Nishant1-Aug-02 2:11
sitebuilderNish Nishant1-Aug-02 2:11 
GeneralRe: Randomic functions ? Pin
Funky Chicken1-Aug-02 2:18
sussFunky Chicken1-Aug-02 2:18 
GeneralRe: Randomic functions ? Pin
Cris1-Aug-02 2:46
Cris1-Aug-02 2:46 
GeneralRe: Randomic functions ? Pin
Chunky Chicken1-Aug-02 2:56
sussChunky Chicken1-Aug-02 2:56 
GeneralRe: Randomic functions ? Pin
[CoY0te]1-Aug-02 3:25
[CoY0te]1-Aug-02 3:25 
GeneralRe: Randomic functions ? Pin
Joaquín M López Muñoz1-Aug-02 7:22
Joaquín M López Muñoz1-Aug-02 7:22 
GeneralVariable Argument list Pin
Wolfram Steinke1-Aug-02 1:37
Wolfram Steinke1-Aug-02 1:37 
GeneralRe: Variable Argument list Pin
Brian Azzopardi1-Aug-02 1:44
Brian Azzopardi1-Aug-02 1:44 
GeneralRe: Variable Argument list Pin
Tim Smith1-Aug-02 2:06
Tim Smith1-Aug-02 2:06 
GeneralRe: Variable Argument list Pin
Anonymous1-Aug-02 2:06
Anonymous1-Aug-02 2:06 
QuestionWhat's my IP? Pin
BlackSmith1-Aug-02 1:34
BlackSmith1-Aug-02 1:34 
AnswerRe: What's my IP? Pin
Brian Azzopardi1-Aug-02 1:39
Brian Azzopardi1-Aug-02 1:39 
Generalgethostname() Doesn't work. Pin
BlackSmith1-Aug-02 2:52
BlackSmith1-Aug-02 2:52 
GeneralRe: gethostname() Doesn't work. Pin
Slinky Chicken1-Aug-02 3:19
sussSlinky Chicken1-Aug-02 3:19 
AnswerRe: What's my IP? Pin
includeh101-Aug-02 4:03
includeh101-Aug-02 4:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.