Call to Non-Static Member Function Without an Object

This C++ error means you are trying to use an instance method without telling the compiler which object should receive the call. A non-static member function has an implicit this pointer, so it needs an object such as widget, this, or a pointer passed as callback context. The right fix depends on whether you meant to call the method immediately, store it for later, or pass it to a callback API.

Use this table to match the code near the error with the appropriate repair.

Symptom Near the Error Likely Cause Correct Approach
ClassName::method() A non-static method is called through the class name Call it on an object: object.method()
method; or ClassName::method The code refers to a method but does not call it Add () for an immediate call, or use a member-function pointer
Passing method to a parameter of type void (*)() A regular function pointer is expected, but the method needs an object Use a static callback wrapper plus an object context
Passing &ClassName::method to void (*)() A member-function pointer is not compatible with a regular function pointer Change the API to accept a member-function pointer or use an adapter
Making the method static removes the error but breaks access to fields The method depended on instance state Keep it non-static and supply an object explicitly

What the Error Means

A non-static member function is not a standalone function; it is an operation that needs a particular object.

Consider this class:

class Meter {
public:
    void add() {
        ++total_;
    }
    void update() {
        add();
    }
private:
    int total_{};
};

Inside update(), the call to add() works because C++ treats it roughly as:

this->add();

The current Meter object supplies the missing object argument.

Outside the class, C++ cannot guess which Meter should be updated. This is invalid:

Meter::add();

There may be many Meter objects, each with its own total_. The compiler needs you to identify one:

Meter meter;
meter.add();

The same issue can appear when you write a member function name without parentheses:

meter.add;

That expression refers to a non-static member function but does not call it. If you meant to execute it now, write:

meter.add();

How to Fix the Error in Normal Method Calls

Call a non-static method through the appropriate object, using parentheses only when the method should run immediately.

Step 1: Identify Whether You Meant to Call or Pass the Method

Look at the expression that triggered the diagnostic.

If the method should run immediately, it needs parentheses and an object:

processor.process();

If the code is inside another non-static method of the same class, the current object is already available:

class Processor {
public:
    void start() {
        process();
    }
private:
    void process() {
        // Work happens here.
    }
};

If you are trying to register work that will run later, do not add () blindly. Parentheses invoke the method immediately; they do not create a callback.

Step 2: Supply the Correct Object

Use either an object reference or an object pointer, depending on what your code has available.

class Report {
public:
    void print() {
        // Print the report.
    }
};
void print_report(Report& report) {
    report.print();
}

With a pointer, use -> after confirming that the pointer is valid:

void print_report(Report* report) {
    if (report != nullptr) {
        report->print();
    }
}

Avoid this form for a non-static method:

Report::print();

The class name identifies the type, not a particular Report object.

Step 3: Keep the Method Non-Static When It Uses Object State

Do not make a method static merely to silence the compiler. A static member function has no implicit this pointer, so it cannot directly use instance fields or call non-static methods.

This is appropriate for behavior that does not depend on object state:

class TextTools {
public:
    static bool is_empty(std::string_view value) {
        return value.empty();
    }
};

This is not appropriate if the operation needs fields belonging to a particular object:

class Connection {
public:
    void reconnect() {
        // Uses this connection's settings and state.
    }
};

Keep reconnect() non-static and call it through a Connection object.

Passing a Member Function to a Callback API

Many callback APIs, especially C libraries and platform APIs, accept an ordinary function pointer such as this:

using Callback = void (*)(void*);
void install_callback(Callback callback, void* context);

A non-static member function cannot be passed directly to that parameter. Its type is different because it needs an object.

This will not work:

install_callback(&Worker::handle_ready, this);

The direct registration fails because handle_ready is a non-static member function.

Use a static wrapper function, often called a thunk or trampoline. The wrapper matches the callback API, receives the object through the context pointer, converts it back to the proper type, and calls the instance method.

class Worker {
public:
    void begin() {
        install_callback(&Worker::on_ready_callback, this);
    }
private:
    static void on_ready_callback(void* context) {
        auto* worker = static_cast<Worker*>(context);
        worker->handle_ready();
    }
    void handle_ready() {
        // Safely use this object's fields and methods.
    }
};

The static callback has the type the API expects:

void (*)(void*)

After recovering the context pointer, worker->handle_ready() supplies the Worker object required to invoke the non-static method.

Keep the Callback Object Alive

Registering the callback is only half of the fix.

If an API can invoke the callback asynchronously, unregister, cancel, or stop the work before destroying the object. Otherwise, the stored void* can point to an object that no longer exists, causing undefined behavior.

A sound callback lifecycle has these parts:

  1. Create the object.
  2. Register the callback and pass that object’s address as context.
  3. Handle each notification through the registered context.
  4. End the registration when notifications are no longer needed.
  5. Release resources associated with the completed registration.

If the library offers no context parameter, it cannot distinguish among multiple object instances through a regular function pointer alone. Prefer an API design that accepts a context pointer or a C++ callable rather than storing the active object in a global variable.

Using Member-Function Pointers Correctly

If you control both sides of the API, you can accept a member-function pointer instead of an ordinary function pointer.

A normal function pointer looks like this:

void run_task();
void (*task)() = run_task;

A member-function pointer includes the class type:

class Timer {
public:
    void tick();
};
void (Timer::*task)() = &Timer::tick;

You still need an object to invoke it:

Timer timer;
(timer.*task)();

For an object pointer, use ->*:

Timer* timer = /* valid Timer object */;
(timer->*task)();

Here is a complete small API that accepts a Timer method:

class Timer {
public:
    void tick() {
        // Update this timer.
    }
};
using TimerAction = void (Timer::*)();
void invoke(Timer& timer, TimerAction action) {
    (timer.*action)();
}
int main() {
    Timer timer;
    invoke(timer, &Timer::tick);
}

Do not cast a member-function pointer to a regular function pointer. They are distinct language types and may have different representations, especially when inheritance is involved.

Matching Parameters, const, and Overloads

The pointer type must match the method signature.

For a method with an argument:

class Logger {
public:
    void write(std::string_view message);
};
using LogAction = void (Logger::*)(std::string_view);

For a const method, include const in the pointer type:

class Document {
public:
    bool is_saved() const;
};
using CheckAction = bool (Document::*)() const;

Overloaded methods can require an explicit type so the compiler knows which overload you mean:

class Panel {
public:
    void refresh();
    void refresh(bool force);
};
using RefreshAction = void (Panel::*)();
RefreshAction action =
    static_cast<RefreshAction>(&Panel::refresh);

Using Lambdas With Modern C++ Callback APIs

A C++ API that accepts std::function, a template callable, or another callable wrapper can accept a lambda that captures this.

void schedule(std::function<void()> job);
class Dashboard {
public:
    void refresh_later() {
        schedule([this] {
            refresh();
        });
    }
private:
    void refresh() {
        // Update this dashboard.
    }
};

The lambda holds the object pointer needed to call refresh().

This is usually clearer than a static wrapper when you control the callback API. But it has the same lifetime requirement: this must remain valid until the scheduled lambda has finished or has been removed.

A captured lambda cannot convert to an ordinary C-style function pointer such as:

void (*callback)()

That type has no place to store the captured object pointer. For those APIs, use the static-wrapper-and-context pattern instead.

Confirm the Fix and Prevent It From Returning

After changing the code, verify these points:

  • The method is called with object.method() or pointer->method().
  • A method name has () only when it should execute immediately.
  • An API expecting void (*)() receives a free function, a static member function, or a noncapturing lambda that matches its exact signature.
  • An API that needs an instance method receives both a callback wrapper and an object context, or accepts a C++ callable.
  • The callback registration has a defined shutdown path.
  • Member-function pointer types match the class, parameters, return type, and const qualification.

When the compiler points at a callback registration line, inspect the parameter type first. The expected type tells you whether the code needs an object call, a member-function pointer, or a static adapter.

Frequently Asked Questions

What is a static method call?

A static method call invokes a function that belongs to the class rather than to one object, such as TextTools::is_empty(value). Static methods have no implicit this pointer, so they cannot directly access non-static fields or call non-static methods without being given an object.

Can a static function access non-static members?

A static function can access non-static members only through an explicit object. For example, a static method can receive Widget& widget and use widget.value_ if it has access to that member. It cannot use value_ by itself because there is no current object.

How do I call a member function through a pointer?

Use -> for an ordinary object pointer, such as widget->update(). For a pointer to member function, use ->*, such as (widget->*action)(), where action has a type like void (Widget::*)().

Why does &Class::method not work as a regular callback?

&Class::method produces a member-function pointer for a non-static method, not a regular function pointer. It still needs a Class object when invoked, while a regular callback type such as void (*)() has no built-in object argument or storage for one.

Why does adding parentheses sometimes make the error worse?

Adding () calls the method immediately. If you are registering a callback, the callback API usually needs a function or callable to save for later, not the result of calling the method now. Use object.method() for immediate work, or pass a compatible callback wrapper for deferred work.