• C++ pass function as argument with parameter


    #include <iostream>
    #include <uuid/uuid.h>
    #include <ctime>
    #include <string>
    #include <sstream>
    #include <unistd.h>
    #include <fstream>
    
    using namespace std;
    
    static char *uuidValue = (char *)malloc(40);
    static char *dtValue = (char *)malloc(20);
    
    char *getTimeNow()
    {
        time_t rawTime = time(NULL);
        struct tm tmInfo = *localtime(&rawTime);
        strftime(dtValue, 20, "%Y%m%d%H%M%S", &tmInfo);
        return dtValue;
    }
    
    char *getUuidValue1()
    {
        uuid_t newUUID;
        uuid_generate(newUUID);
        uuid_unparse(newUUID, uuidValue);
        return uuidValue;
    }
    
    void invokeFunc(void(*funcName)(int));
    void printUuidValue8(int len);
    
    int main()
    {
        invokeFunc(printUuidValue8);
        return 0;
    }
    
    void printUuidValue8(int len)
    { 
        for(int i=0;i<len;i++)
        {
            cout<<"I="<<i<<",value="<<getUuidValue1()<<",now is "<<getTimeNow()<<endl;
            sleep(1);
        }
        cout<<"Finished in printUuidValue8() and now is "<<getTimeNow()<<endl;
        free(dtValue);
        free(uuidValue);
    }
    
    void invokeFunc(void(*funcName)(int))
    {
        int len=100;
        (*funcName)(len);
    }
  • 相关阅读:
    CSS hack
    字符串中常用的方法
    排序算法
    拾遗
    数组类型检测
    数组常用的方法
    go 文件服务器(标准库) 添加关机,睡眠,退出功能
    go cmd 交互 初始化执行某些命令
    go 内网IP及外网IP获取
    go 快排实现
  • 原文地址:https://www.cnblogs.com/Fred1987/p/15732863.html
Copyright © 2020-2023  润新知