Results 1 to 6 of 6

Thread: Problem with classes

  1. #1
    ChimpFace9000
    Guest

    Post Problem with classes

    Im still learning classes, so could someone please tell me why i get this error...

    Code:
    Error E2235 wndmain.cpp 14: Member function must be called or its address taken in function wndmain::wndmain()
    Heres the files...

    wndmain.cpp
    Code:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include "wndmain.h"
    
    wndmain::wndmain()
    {
    	WNDCLASSEX WndClassEx;
    
    	hIconMain	= LoadIcon(NULL, IDI_APPLICATION);
    	hCursorArrow	= LoadCursor(NULL, IDC_ARROW);
    
    	WndClassEx.cbSize	= sizeof(WNDCLASSEX);
    	WndClassEx.lpfnWndProc	= WndProc;
    	WndClassEx.style	= CS_HREDRAW | CS_VREDRAW;
    
    	return;
    }
    
    wndmain::~wndmain()
    {
    	DestroyIcon(hIconMain);
    	DestroyCursor(hCursorArrow);
    
    	return;
    }
    
    LRESULT	CALLBACK wndmain::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	return(0);
    }
    wndmain.h
    Code:
    class wndmain
    {
    public:
    		wndmain();
    		~wndmain();
    
    protected:
    	LRESULT	CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
    
    	static HICON	hIconMain;
    	static HCURSOR	hCursorArrow;
    };
    The error is with this line in wndmain.cpp...
    Code:
    WndClassEx.lpfnWndProc	= WndProc;
    Anything would be helpful.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    2 solutions:

    1. make the callback function static and virtually inherit the class to extend it.
    2. don't contain the function, in other words have a function pointer.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    ChimpFace9000
    Guest
    How do i do either of those?

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    1. add static and virtual specifiers to the declaration of the callback, then derive a class using virtual functions
    2. add a member specifying the function pointer to a LRESULT CALLBACK (*proc)(HWND, UINT , WPARAM , LPARAM ); and use it for WNDCLASSEX. you could initialize this to a default proc in the constructor or have it passed there, or/and use accessors.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    ChimpFace9000
    Guest
    I spent the last little while trying to do either of those, and i realized, i have no idea what to do. I have a pretty good understanding of c and c++, just not when it comes to pointers and inheritance (dont even know what that is). Could you show an example please. Thanks.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221

    Thumbs up

    Inheritance is a very very important concept in object oriented programming, if you learn it now, you'll have benefit of it the rest of your life, have a look at Sam's teach yourself C++ in 21 days and pick up what you missed.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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