Home

stdaddressof

std::addressof is a utility in the C++ standard library that returns the actual memory address of an object, bypassing any overloaded address-of operator. It is designed to obtain a true pointer to an object even when a class defines a custom operator&.

The function is declared in the <memory> header and is available since C++11. Its signature is template<class

std::addressof is particularly important when a class overloads operator& to return a proxy or otherwise alter

Typical usage is straightforward: given an lvalue obj of some type T, std::addressof(obj) yields a T* that

Notes: std::addressof requires an lvalue of type T; it cannot take a temporary. It is also useful

T>
constexpr
T*
addressof(T&
r)
noexcept.
It
yields
a
pointer
to
the
referred
object,
regardless
of
any
user-defined
operator&.
The
operation
is
constexpr
and
noexcept,
making
it
usable
in
constant
expressions
and
in
contexts
where
exceptions
must
be
avoided.
the
meaning
of
address
taking.
In
such
cases,
using
the
built-in
address
operator
(&)
would
invoke
the
overloaded
operator,
not
the
actual
memory
address.
std::addressof
provides
a
standard,
portable
way
to
obtain
the
real
address
of
the
object.
points
to
the
original
object.
This
is
commonly
used
in
low-level
code,
in
library
implementations,
or
when
interacting
with
APIs
that
require
the
true
object
address.
in
situations
where
operator&
is
deleted
or
unavailable.
See
also
the
built-in
address-of
operator
and
related
utilities
in
<memory>.