创建从参数变量名称 [英] Creating variable names from parameters
本文介绍了创建从参数变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能创建的变量列表名称中的一个参数?
事情是这样的:
为(N = 0; N< VAL; N ++)
INT var'n'= 0;
解决方案
一般情况下,没有。
变量名称必须固定在编译时。他们不能依赖于运行时输入。因此,如果 N
在你的例子是输入(比如,从用户),你想不能做什么。
如果你知道 N
静态,你可以做的preprocessor或模板,或两者的招数,但你可能并不想:如何将你用你的 N
变量?
Is it possible to create a list of variables with a parameter in the name? Something like this:
for(n=0; n< val; n++)
int var'n'=0;
解决方案
Usually, no.
Variables names must be fixed at compile-time. They cannot depend on run-time input. So if the n
in your example is input (say, from the user), what you want cannot be done.
If you know n
statically, you could do tricks with the preprocessor, or templates, or both, but you probably don't want to: How would you get to use your n
variables?
这篇关于创建从参数变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文