2015年5月22日金曜日

nullptr(C++)

C++ではNULLは0でマクロ定義されており、プリミティブ型として扱われる。

nullptrはNULLをポインタ化したものであり、ポインタとして扱いたいときに利用する。

//
// nullptr.cpp
// CplusplusPractice
//
// Created by masai on 2015/05/22.
// Copyright (c) 2015年 masai. All rights reserved.
//
#include <iostream>
using namespace std;
void func(void* p){
cout << "void*" << endl;
}
void func(int a){
cout << "int" << endl;
}
void func(nullptr_t p){
cout << "nullptr_t" << endl;
}
int main(){
func(12);
func(nullptr);
}
view raw nullptr.cpp hosted with ❤ by GitHub

0 件のコメント:

コメントを投稿