C ++ - 编程调用正确的函数参数 [英] C++ - Programatically call correct function parameters

查看:109
本文介绍了C ++ - 编程调用正确的函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我有一个问题。说我有这个代码:

Ok, I have a question. Say I have this code:

int myfunc(int arg-a, int arg-b); 
int mywrapperfunc(obj a, obj b);

mywrapperfunc应该包装myfunc。 mywrapperfunc放弃第一个参数,第二个参数是一个数组。然后我使用数组项作为参数。但是说,我不知道有多少参数myfunc需要,我也不知道有多少项目在数组类型对象(b)。我将如何编程使用正确的args数调用myfunc?被移交的args的数目将与数组类型对象中的项目数相同。
EDIT:arg-a和arg-b应该来自数组类型对象。我把对象分成args。
编辑:好的,我试图用一些有意义的包装Cython,隐藏大多数后台作业。

mywrapperfunc is supposed to wrap myfunc. mywrapperfunc discards the first argument and takes the second, which is an array. I then uses the array items as parameters. But say I don't know how many parameters myfunc takes, nor do I know how many items are in tthe array-type object(b). How would I programatically call myfunc with the correct number of args? The number of args handed over would be the same as the number of items in the array-type object. arg-a and arg-b are supposed to come from the array-type object. I split the object into the args. Ok, ok, I'm trying to wrap Cython with some sense invloved, hiding most backround jobs.

推荐答案

p>它被称为 reflection ,你不能用c ++做到这一点。使用其他语言,如java或c#。

It's called reflection, you cannot do this with c++. Use another languages like java or c# for that.

这篇关于C ++ - 编程调用正确的函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆