008 区别 : NULL nullptr

 

 

/*
目录:
   一: NULL本质
   二: nullptr本质
*/

 

一: NULL本质

#ifndef NULL
    #ifdef __cplusplus
        #define NULL 0
    #else
        #define NULL ((void *)0)
    #endif
#endif

 

二: nullptr本质

#include "stdafx.h"
#include <iostream>

void fun(int)
{
    std::cout << "fun(int)" << std::endl;
}
void fun(void *)
{
    std::cout << "fun(void *)" << std::endl;
}

int main(int argc, char *argv[])
{
    fun(NULL);        // 类型 : NULL - int
    fun(nullptr);    // 类型 : nullptr - void *

    return 0;
}

/*
// result
fun(int)
fun(void *)
*/

 

posted @ 2019-09-11 19:37  火焰马  阅读(137)  评论(0编辑  收藏  举报