CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Jan 2007
    Posts
    38

    [SOLVED] Calling non-static member functions from within a static member function.

    Hello all. I'm not sure if this is the right forum to post this in, so if it isn't I apologize in advance.

    I'm making a windows program that is entirely wrapped in a class. So this also includes my window procedure, which had to be defined as a static function. Like this:

    Code:
    class cUTool2004
    {
    public:
    	cUTool2004(void);
    	~cUTool2004(void);
    	DWORD Setup(HINSTANCE hInstance, LPSTR lpCmdLine, int nCmdShow);
    	DWORD Cleanup(void);
    
    private:
    	HWND hWindow;
    	HFONT hfMainTitle;
    	HFONT hfMainNotInstalled;
    	int iMainTab;
    	int iRegistryTab;
    	int iDemosTab;
    	bool bUTFound;
    	bool UTisInstalled(void);
    	int LoadTab(int iTab);
    	int LoadMainTab(void);
    	int UnloadTab(int iTab);
    	int UnloadMainTab(void);
    	static LRESULT WndMsgHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    };
    Now, I'm trying to call UnloadTab() from WndMsgHandler() but this gives me compile error C2352: 'cUTool2004::UnloadTab' : illegal call of non-static member function. I guess this is because non-static functions are supposed to get the hidden 'this' pointer, but because WndMsgHandler is static it doesn't have the 'this' pointer. Correct?
    Does this then mean that non-static functions can't be called from static ones? That would mean changing many of my memberfunctions to statics... That can't be right, can it? Or are there other ways around this?

    Bah, this is probably just some stupid oversight of me... Anyway, thanks in advance for any pointers (LOL PUN) in the right direction.
    Last edited by Jehjoa; March 5th, 2007 at 09:20 AM. Reason: Problem has been solved.
    I am a beginning C++ Win32 programmer with LOTS of questions. Hopefully matching answers can be found here...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured