zoukankan      html  css  js  c++  java
  • Item 17. 函数与数组声明上的比较

    Item 17. Dealing with Function and Array Declarators

    函数与数组的声明能够放在一起来比较,是因为它们有相同的遭遇,同是天涯沦落人。

    ------------------------------------------------------------------
    1、两种函数声明
    例如:
     int *f1(); // 返回类型为int* 的函数
     int (*fp1)(); // 指向返回类型为int的函数之指针

    2、两种数组
    例如:
    const int N = 12;
    int *a1[N]; // 有N个int*的数组
    int (*ap1)[N]; // 指向有N个int的数组之指针

    3、推而广之
    int (**ap2)[N]; // ptr to ptr to array of N ints
    int *(*ap3)[N]; // ptr to array of N int *
    int (**const fp2)() = 0; // const ptr to ptr to func
    int *(*fp3)(); // ptr to func that returns int *

    4、当函数遇上数组的时候
    int (*afp2[N])(); // array of N ptr to func that returns int

    另一种写法
    typedef int (*FP)(); // ptr to func that returns int
    FP afp3[N]; // array of N FP, same type as afp2

    5、当引用和const出现后:
    int aFunc( double ); // func
    int (&rFunc)(double) = aFunc; // ref to func
    int (*const pFunc)(double) = aFunc; // const ptr to func

     

  • 相关阅读:
    Spring-12-spring整合Mybatis
    Spring-11-AOP面向切面编程
    jQuery选择器之表单元素选择器
    phpsmarty分配变量
    angular
    ajax 第四步
    ajax第三步
    php+ajax+jq
    二十三种设计模式[4]
    二十三种设计模式[3]
  • 原文地址:https://www.cnblogs.com/aiwz/p/6333242.html
Copyright © 2011-2022 走看看