Why do I need a static class member? What are the advantages and disadvantages of it?

Is there any way that I can have non-static member fuction without doing anything outside of the class (such as passing an instance)?

class Control
{
    private:
        HMENU ID;
        HWND Handle, Parent;
        std::string Class, Title;
        DWORD dwExStyle, dwStyle;
        Point Location;
        int Width, Height;
        std::array<std::function<void(void)>, 6> Functions;

    public:
        Control(DWORD dwExStyle, std::string Class, std::string Title, DWORD dwStyle, Point Location, int Width, int Height, HWND Parent, HMENU ID, HINSTANCE Instance, void* LParam);
        virtual ~Control();

        virtual LRESULT __stdcall Subclass(HWND window, UINT msg, WPARAM wParam, LPARAM lParam);
};


Control::~Control() {}

//Constructor here..

//Subclass..

LRESULT __stdcall Control::Subclass(HWND Window, UINT Msg, WPARAM wParam, LPARAM lParam)
{
    //WNDPROC SubProc = reinterpret_cast<WNDPROC>(GetWindowLongPtr(Window, GWLP_USERDATA));

    switch(Msg)
    {

        case WM_DESTROY:
            RemoveWindowSubclass(Window, Subclass, 0);
        break;

        default:
            return CallWindowProc(Subclass, Window, Msg, wParam, lParam);
    }
}

In my subclass function, the line: RemoveWindowSubclass(Window, Subclass, 0); gives me the error cannot convert Control::Subclass to SUBCLASSPROC.

I know that inorder to do so, I need to make it static.

So how can I have a non-static callback within my class? I know it can be done with a Lambda because I tried it, but is there any other way without having to do anything outside my class (such as passing an instance)?

I'm trying to emulate the C#'s control class in WINAPI.

static class methods do not have an instance, they are always present in memory just like a normal global function. When you pass a function as a parameter the function is passed by address very similar to arrys and the address must be known at compile time, not runtime. The address of non-static class methods is only known at runtime when an instance of the class is created.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.