标签: function

有没有办法在c++中通过名称动态调用函数

我有一个名为 so, void F1(), void F2().....的函数列表

我要求用户输入一个数字,它会调用相应的函数。所以如果他们输入5它就会调用F5().

我想知道是否有一种方法可以通过将用户输入附加到函数调用来做到这一点,而不是使用一个很长的 switch 语句。像下面的代码一样

std::cout << "Please enter the number of the function you wish to call " << std::endl;

std::cin >> choice;

functionToCall = "F" + choice;
Run Code Online (Sandbox Code Playgroud)

c++ function c++14

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

Unity,从按钮 onClick 调用 IEnumerator 函数

我尝试IEnumerator通过单击按钮调用函数,这样我就可以返回一些内容,但我无法从检查器的On Click()下拉菜单中选择该函数。

我尝试IEnumerator从另一个函数调用 并将该函数分配给按钮,但不起作用!

显然我不能yield returnvoid函数中执行此操作。

那么有人可以好心地教我该怎么做吗?

非常感激!

ienumerator function onclick buttonclick unity-game-engine

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

如果在 localeCompare 函数中设置 numeric:true 会有任何变化吗

我有带有数字和字符串类型的表值,并且想知道设置数字 true 会带来对列中字符串值进行排序的任何更改

html javascript function

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

将函数作为类中的参数传递

我在 C++ 中将函数作为参数传递时遇到问题。我在这里重新创建了一个最小的工作示例:

#include <iostream>
using namespace std;

void print(const double &func(double)) {
  cout << func(1) << endl;
}

class Obj {
  public:
  double MyFunction(double x);
  void PrintFunction();
};

void Obj::PrintFunction(){
  print(MyFunction);
}

double Obj::MyFunction(double x) {
  return x + 1;
}

int main() {
  Obj object;
  object.PrintFunction();
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,整体结构看起来很奇怪,但在完整的代码中更有意义(具体来说,我理想地寻找一个不涉及重组函数所有权的解决方案)。编译时出现错误error: invalid use of non-static member function double Obj::MyFunction(double),这表明我的调用方式有问题print(MyFunction)。我粗略的理解是MyFunction不能单独调用,但是没有包含多少指针、引用等,都成功地得到了代码进行编译。我应该如何正确打电话MyFunction

c++ function

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

强制 Powershell 函数返回数组


如何强制 Powershell 函数返回数组?
这个简单的函数例如,如果“C:\Newfolder”仅包含 1 个元素,则它不会返回数组。

function Get-AlwaysArray
{
    $returnArray = gci "C:\New folder"
    Write-Output $returnArray
}
(Get-AlwaysArray).Gettype()
Run Code Online (Sandbox Code Playgroud)

已经有一个线程在这里有一个非常好的赞成答案,但不幸的是,没有一个答案有效。
这是我尝试过的:

function Get-AlwaysArray {
    [Array]$returnArray = gci "C:\New folder"
    Write-Output $returnArray   
}
(Get-AlwaysArray).Gettype()

function Get-AlwaysArray {
    $returnArray = @(gci "C:\New folder")
    Write-Output @($returnArray)   
}
(Get-AlwaysArray).Gettype()

function Get-AlwaysArray {
    $returnArray = @(gci "C:\New folder")
    Write-Output @($returnArray | Where-Object {$_})   
}
(Get-AlwaysArray).Gettype()

function Get-AlwaysArray {
    [Object[]]$returnArray = @(gci "C:\New folder")
    Write-Output @($returnArray | Where-Object {$_})   
}
(Get-AlwaysArray).Gettype()
Run Code Online (Sandbox Code Playgroud)

唯一可行的方法是

function Get-AlwaysArray { …
Run Code Online (Sandbox Code Playgroud)

powershell types return function

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

从连接字符串名称调用 Python 函数名称

我想通过连接“字符串”+变量+“字符串”创建一个 def 函数名称并调用该 def 函数。

为了简单起见,我目前正在使用这个压缩版本的代码来类似地完成任务,并且我想最小化函数 do_update(a) 的硬代码内容:

ROTATE = '90'

ROT20 = [
[0, 0, 0, 0, 0, 0, 0, 0],
[126, 129, 153, 189, 129, 165, 129, 126],
[126, 255, 231, 195, 255, 219, 255, 126],
[0, 8, 28, 62, 127, 127, 127, 54],
[0, 8, 28, 62, 127, 62, 28, 8],
[62, 28, 62, 127, 127, 28, 62, 28],
[62, 28, 62, 127, 62, 28, 8, 8],
[0, 0, 24, 60, 60, 24, 0, 0],
];

def …
Run Code Online (Sandbox Code Playgroud)

python function

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

python中函数名的长度有限制吗?

只要我符合定义函数名称的规则,每个长度似乎都有效。到底限制是什么,或者是否存在限制?

python function

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

Excel 函数 =NORM.S.INV(rand()) 在 R 中的函数是什么?

我需要转换Excel函数=NORM.S.INV(rand())。我尝试使用 rnorm(1000,0,1),但结果在分布意义上似乎不正确。Excel 的 NORM.S.INV(rand()) 的 R 函数应该是什么?

我想要 rnorm(1,0,1) 或 qnorm(runif(1)) 的分布

谢谢你的帮助!

excel r function

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

-C 中的 W 隐式函数声明

我不明白这是如何隐式的,我在每个函数中返回一个 int ,并且所有函数都在主函数之前。老实说,第一次看到这个,有人给我发了很长的代码来调试,其中有很多错误,但为什么这不起作用,我错过了什么

int findString(char matrix[ROW][COLUNM],char str1[],int length){
    int left,right,top,down,result;



    left=left2_right(matrix,str1,length);-THESE 4 CALLS GIVE THE WARNINGS
    right=rigth2_left(matrix,str1,length);
    top=top_bottom(matrix,str1,length);
    down=bottom_top(matrix,str1,length);

    if(left != -1 ){result=left;}
    if(right != -1 ){result=right;}
    if(top != -1 ){result=top;}
    if(down != -1 ){result=down;}

return result;
}
Run Code Online (Sandbox Code Playgroud)

这是其中一项功能

int left2_right(char matrix[ROW][COLUNM],char str1[],int length){

    int i = 0, j, counting = 0, wordcnt;
    //int length = computeLength(str1);   //returns legth of string   
    int index = -1;

    for (i = 0; i < ROW; i++)
    {
        for (j = 0; j < …
Run Code Online (Sandbox Code Playgroud)

c arrays declaration function

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

使用 sendgrid 从 firebase 获取附件

谁能帮我这个?我正在尝试使用 Firebase 函数中的 SendGrid 将文件从 Firebase 存储附加到电子邮件。任何帮助将非常感激。我已经做到了这一点:

export const sendEmail2 = functions.https.onCall(async (data, context) => {
    if (!context.auth) {
        throw new functions.https.HttpsError('failed-precondition', 'You must be logged in!');
    }
    const toEmail = data.toEmail;
    const fromEmail = data.fromEmail;
    const subject = data.subject;
    const body = data.body;
    const msg: any = {
        to: toEmail,
        from: fromEmail,
        subject: subject,
        html: body,
    };
    if (data.cc) {
        msg.cc = data.cc;
    }
    if (data.attachments) {
        msg.attachments = [];
        let content;
        data.attachments.forEach(
            async (att: any) => {
                const …
Run Code Online (Sandbox Code Playgroud)

function sendgrid firebase

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