C++ Logo

std-proposals

Advanced search

[std-proposals] Auto-deduction of return value for derived functions.

From: Renji Panicker <renjipanicker_at_[hidden]>
Date: Sat, 14 Feb 2026 09:02:40 +0530
Hi all,

I am floating this idea here to get some early feedback and suggestions
before I work on it further.

In C++, the overriding function of a base class virtual function should be
permitted to specify 'auto' as its return type.

Example:
class Base {
    virtual std::vector<std::string> getList() = 0;
}:

class Derived : public Base {
    virtual auto getList() override {
        // do something
    }
}:

Per existing C++ rules:
1. The return type does not contribute to the function signature.
2. The return type of the derived function must necessarily always match
that of the base class virtual function.

So we can mark it as ‘auto’ and let the compiler infer the type from the
base class virtual function.

This promotes stronger adherence to the DRY (Don’t Repeat Yourself)
principle.

Let me know what you think of this.

Regards,
-/renji
https://linkedin.com/in/renjipanicker

Received on 2026-02-14 03:32:53