Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在AngelScript中使用全局函数_C++_Angelscript - Fatal编程技术网

C++ 在AngelScript中使用全局函数

C++ 在AngelScript中使用全局函数,c++,angelscript,C++,Angelscript,我在C++应用程序中使用全局函数时遇到了一个问题 在我的.cpp文件中,我具有以下功能: int multi(int x, int y) { int z = x * y; cout << x << endl; cout << y << endl; return z; } 在.as文件中,我调用如下函数: multi(1, 2); 在这种情况下,我希望x为1,y为2,但当我用cout打印值时,它类似于x=43180

我在C++应用程序中使用全局函数时遇到了一个问题

在我的.cpp文件中,我具有以下功能:

int multi(int x, int y)
{
    int z = x * y;
    cout << x << endl;
    cout << y << endl;
    return z;
}
在.as文件中,我调用如下函数:

multi(1, 2);
在这种情况下,我希望x为1,y为2,但当我用cout打印值时,它类似于x=4318096和y=4318100


我不知道我的错误在哪里。非常感谢您的帮助。

您注册此函数时出错。应该是:

engine->RegisterGlobalFunction("int multi(int, int)", asFUNCTION(multi), asCALL_CDECL);
engine->RegisterGlobalFunction("int multi(int, int)", asFUNCTION(multi), asCALL_CDECL);
Out表示此函数将使用此参数作为输出。

它应该是:

engine->RegisterGlobalFunction("int multi(int, int)", asFUNCTION(multi), asCALL_CDECL);
engine->RegisterGlobalFunction("int multi(int, int)", asFUNCTION(multi), asCALL_CDECL);

当您使用out时,它希望您设置out值。它在进入函数之前不会被设置。我希望你按照我说的去做,它将被设定,而不期望它被设定。祝你好运。

非常感谢你,我相信事情会这么简单