Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions docs/cpp/static-function-call-operator.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
description: "Learn how to declare and use the static function call operator in C++."
title: "Static function call operator (C++)"
ms.date: 08/19/2026
title: "Static function call operator (C++23)"
ms.date: 08/26/2026
ai-usage: ai-assisted
helpviewer_keywords: ["static function call operator [C++]", "static operator() [C++]", "operator overloading [C++]"]
---

# Static function call operator (C++)

In C++23, you can declare the function call operator (`operator()`) as a static member function. A static function call operator doesn't have an implicit object parameter. Use it when a callable type doesn't need to access instance data.
In C++23, you can declare the function call operator, `operator()`, as a static member function. A static function call operator doesn't have an implicit object parameter. Use it when a callable type doesn't need to access instance data.

Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` compiler option.
Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` or `/std:c++23preview` compiler option.

## Syntax

Expand All @@ -22,6 +22,7 @@ You can also declare the function call operator generated for a lambda expressio

```cpp
[](parameter-list) static { function-body }
[] static { function-body }
```

## Remarks
Expand All @@ -30,13 +31,13 @@ A static function call operator doesn't have a `this` pointer. It can't be `virt

You can call a static function call operator by using an object of its class, which allows the object to work as a function object. You can also call it by using its qualified name. Taking its address produces a regular function pointer instead of a pointer-to-member function.

A lambda expression can specify `static` after its parameter list. A static lambda can't have captures or be declared `mutable`. Declaring a captureless lambda doesn't make it static automatically; you must specify `static` to opt in to this behavior.
A lambda expression can specify `static` after its parameter list. When the lambda has no parameters, you can omit the empty parameter list and specify `static` after the lambda introducer (`[]`). A static lambda can't have captures or be declared `mutable`. Declaring a captureless lambda doesn't make it static automatically; you must specify `static` to opt in to this behavior.

The feature-test macro `__cpp_static_call_operator` is defined when the static function call operator is available.

## Example
## Static function call operator example

The following example defines a stateless function object and calls its static function call operator in three ways:
The following example defines a stateless function object and calls its static function call operator in three ways. It also defines a static lambda expression and calls it:

```cpp
// Compile with: /std:c++latest
Expand All @@ -63,6 +64,7 @@ int main()
std::cout << "multiply_function(5, 5) = "
<< multiply_function(5, 5) << std::endl;

// A static lambda expression that doubles its argument
auto twice = [](int value) static noexcept
{
return value * 2;
Expand Down
16 changes: 11 additions & 5 deletions docs/cpp/static-subscript-operator.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
description: "Learn how to declare and use the static subscript operator in C++."
title: "Static subscript operator (C++)"
ms.date: 08/19/2026
ms.date: 08/26/2026
ai-usage: ai-assisted
helpviewer_keywords: ["static subscript operator [C++]", "static operator[] [C++]", "operator overloading [C++]"]
---

# Static subscript operator (C++)

In C++23, you can declare the subscript operator (`operator[]`) as a static member function. A static subscript operator doesn't have an implicit object parameter. Use it when a subscript operation doesn't need to access instance data.
In C++23, you can declare the subscript operator, `operator[]`, as a static member function. A static subscript operator doesn't have an implicit object parameter. Use it when a subscript operation doesn't need to access instance data.

Support for this feature was introduced in Visual Studio 2022 version 17.14 (MSVC 14.44). Use the `/std:c++latest` compiler option.

Expand All @@ -22,11 +22,17 @@ static return-type operator[](parameter-list);

A static subscript operator doesn't have a `this` pointer. It can't be `virtual` or have a cv-qualifier (`const` or `volatile`) or ref-qualifier (`&`, `&&`).

You can call a static subscript operator by using an object of its class, which allows the object to use subscript syntax. You can also call it by using its qualified name. Taking its address produces a regular function pointer instead of a pointer-to-member function.
You can call a static subscript operator through an object or by using its qualified name. Taking its address produces a regular function pointer instead of a pointer-to-member function.

The feature-test macro `__cpp_static_call_operator` is defined when the static subscript operator is available.
The feature-test macro `__cpp_multidimensional_subscript` has a value of at least `202211L` when the static subscript operator is available. Simply checking whether the macro is defined is insufficient because its earlier value of `202110L` covers multidimensional subscripting but not `static operator[]`:

## Example
```cpp
#if defined(__cpp_multidimensional_subscript) && __cpp_multidimensional_subscript >= 202211L
// static subscript operator is available
#endif
```

## Static subscript operator example

The following example defines a stateless type that calculates powers of two and calls its static subscript operator in three ways:

Expand Down
2 changes: 1 addition & 1 deletion docs/cpp/subscripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ms.assetid: eb151281-6733-401d-9787-39ab6754c62c
---
# Subscripting

The subscript operator (**[ ]**), like the function-call operator, is a binary operator. Before C++23, the subscript operator must be a nonstatic member function. In C++23 and later, it can be a static member function. For more information, see [Static subscript operator](static-subscript-operator.md).
The built-in subscript operator (**[ ]**) is a binary operator. Before C++23, you had to overload the subscript operator (`operator[]`) by using a nonstatic subscript operator member function. In C++23 and later, you can also overload it by using a static subscript operator member function. For more information, see [Static subscript operator](static-subscript-operator.md).

The argument can be any type and designates the desired array subscript.

Expand Down