小编Hei*_*ich的帖子

bash参数解析函数

解析函数中的bash脚本参数是一种解决方法

run命令:./ script.sh -t -r -e

脚本:

#!/bin/sh
# parse argument function
parse_args() {
echo "$#"   #<-- output: 0
}


# main
echo "$#"   #<-- output: 3

# parsing arguments
parse_args
Run Code Online (Sandbox Code Playgroud)

bash arguments function

3
推荐指数
1
解决办法
1454
查看次数

c ++函数(带体)作为参数

我想传递一个函数作为参数.我知道你可以传递一个函数指针,就像我的例子中的第一个测试一样,但是可以像我的第二次测试一样传递一个hold函数(不是指针)吗?

#include <iostream>

using namespace std;


/* variable for function pointer */
void (*func)(int);

/* default output function */
void my_default(int x) {
    cout << "x =" << "\t" << x << endl << endl;
}


/* entry */
int main() {
    cout << "Test Programm\n\n";

    /* 1. Test - default output function */
    cout << "my_default\n";
    func = &my_default;   // WORK! OK!
    func(5);

    /* 2. Test - special output function 2 */
    cout << "my_func2\n";
    func =  void my_func1(int …
Run Code Online (Sandbox Code Playgroud)

c++ function argument-passing

2
推荐指数
1
解决办法
146
查看次数

标签 统计

function ×2

argument-passing ×1

arguments ×1

bash ×1

c++ ×1