GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::polymorphic::operator-> - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. memory
  3. polymorphic
  4. operator->

最終更新日時: 2026年07月23日 11時34分53秒 (JST)
Raclamusi が更新

履歴 編集

function
<memory>

std::polymorphic::operator->(C++26)

constexpr const_pointer operator->() const noexcept; // (1)
constexpr pointer operator->() noexcept;             // (2)

概要

所有するオブジェクトのメンバへ、基底型Tとしてアクセスするためのポインタを取得する。

事前条件

*thisが無効値状態でないこと。

戻り値

所有するオブジェクトを指すポインタ。

例外

投げない。

例

#include <cassert>
#include <memory>

struct Base {
  virtual ~Base() = default;
  virtual int f() const { return 0; }
};
struct Derived : Base {
  int x = 42;
  Derived() = default;
  Derived(int x) : x(x) {}
  int f() const override { return x; }
};

int main()
{
  std::polymorphic<Base> a{std::in_place_type<Derived>};
  assert(a->f() == 42);  // 基底型Baseのメンバへアクセス(仮想ディスパッチ)
}

出力

バージョン

言語

  • C++26

処理系

  • Clang: 22 ❌
  • GCC: 16.1 ✅
  • Visual C++: 2026 Update 2 ❌

関連項目

  • std::polymorphic

参照

  • P3019R14 indirect and polymorphic: Vocabulary Types for Composite Class Design
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.