zoukankan      html  css  js  c++  java
  • 23.引用函数指针

     1 #include <iostream>
     2 #include <cstdlib>
     3 using namespace std;
     4 
     5 //指行system指令
     6 void gocmd(const char *cmd)
     7 {
     8     system(cmd);
     9 }
    10 
    11 //输出cmd指令
    12 void showcmd(const char *cmd)
    13 {
    14     cout << cmd << endl;
    15 }
    16 
    17 //改变函数指针的指向
    18 void change(void(*&p)(const char *cmd))
    19 {
    20     p = showcmd;
    21 }
    22 
    23 //返回值是函数指针引用
    24 void (* &getp())(const char *cmd)
    25 {
    26     void(*p)(const char *cmd)(gocmd);
    27     return p;
    28 }
    29 
    30 void main()
    31 {
    32     //改变函数指针的指向
    33     /*void(*p)(const char *cmd)(gocmd);
    34     change(p);
    35     p("calc");*/
    36     void(*p)(const char *cmd) = getp();
    37 
    38     p("calc");
    39     cin.get();
    40 }
  • 相关阅读:
    两种称谓
    HDU 1074

    Educational Codeforces Round 44
    nowcoder—Beauty of Trees
    nowcoder-练习赛16
    c++作业-8
    差的东西
    nowcoder-挑战赛14
    BZOJ2548 [CTSC2002] 灭鼠行动
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8545763.html
Copyright © 2011-2022 走看看