名前空間
変種
操作

Pointer types

提供: cppreference.com
< cpp‎ | language

 
 
C++言語
一般的なトピック
フロー制御
条件付き実行文
繰り返し文 (ループ)
ジャンプ文
関数
関数宣言
ラムダ関数宣言
inline 指定子
例外指定 (非推奨)
noexcept 指定子 (C++11)
例外
名前空間
指定子
decltype (C++11)
auto (C++11)
alignas (C++11)
記憶域期間指定子
初期化
代替表現
リテラル
ブーリアン - 整数 - 浮動小数点
文字 - 文字列 - nullptr (C++11)
ユーザ定義 (C++11)
ユーティリティ
属性 (C++11)
typedef 宣言
型エイリアス宣言 (C++11)
キャスト
暗黙の変換 - 明示的な変換
static_cast - dynamic_cast
const_cast - reinterpret_cast
メモリ確保
クラス
クラス固有の関数特性
特別なメンバ関数
テンプレート
その他
 

目次

[編集] 構文

cv type * cv identifier (1)
return ( * identifier ) ( param_types ) (2)
return ( class_name :: * identifier ) ( param_types ) cv_qualifier (3)
type & identifier (4)
type && identifier (5) (C++11およびそれ以降)

[編集] 説明

#データへのポインタ
Original:
# Pointer to data
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
関数へのポインタ#
Original:
# Pointer to function
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
メンバ関数へのポインタ#
Original:
# Pointer to member function
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#リファレンス
Original:
# Reference
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#r値参照
Original:
# r-value reference
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] ノート

  • cv*の前にある場合、ポイント先のオブジェクトが影響を受けます.
    Original:
    If cv is before *, the pointed-to object is affected.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
  • cv*後であれば、ポインタが影響を受けている.
    Original:
    If cv is after *, the pointer is affected.
    The text has been machine-translated via Google Translate.
    You can help to correct and verify the translation. Click here for instructions.
Syntax meaning
const T * pointer to constant object
T const * pointer to constant object
T * const constant pointer to object
const T * const constant pointer to constant object
const T & reference to constant object

[編集]

#include <iostream>
 
struct Class
{
    int data_member;
 
    void member_function(int i) const
    {
        std::cout << "Member function: " << i << std::endl;
    }
 
    static void static_member_function ( int i )
    {
        std::cout << "Static member function: " << i << std::endl;
    }
};
 
void global_function ( int i )
{
        std::cout << "Global function: " << i << std::endl;
}
 
int main()
{
    Class object;
 
    Class *ptr = &object;
    ptr->member_function(1);
 
    Class &ref = object;
    ref.data_member = 2;
    std::cout << "object.data_member = " << object.data_member << std::endl;
 
    void (Class::*ptr_to_memfun)(int) const = &Class::member_function;
    (object.*ptr_to_memfun)(3);
    (ptr->*ptr_to_memfun)(4);
 
    void (*ptr_to_fun)(int) = Class::static_member_function;
    ptr_to_fun(5);
 
    ptr_to_fun = global_function;
    ptr_to_fun(6);
 
}

出力:

Member function: 1
object.data_member = 2
Member function: 3
Member function: 4
Static member function: 5
Global function: 6