Questions tagged «compile-time-constant»

13
Java switch语句:需要常量表达式,但它是常量
因此,我正在研究具有一些静态常量的此类: public abstract class Foo { ... public static final int BAR; public static final int BAZ; public static final int BAM; ... } 然后,我想一种基于常量获取相关字符串的方法: public static String lookup(int constant) { switch (constant) { case Foo.BAR: return "bar"; case Foo.BAZ: return "baz"; case Foo.BAM: return "bam"; default: return "unknown"; } …

5
如何在for循环中使用const变量来生成模板类?
我有一个类似的代码 template <size_t N> class A { template <size_t N> someFunctions() {}; }; 现在,我想创建该类的实例,并在for循环中为一组许多值(例如, // in main() int main() { for (int i = 1; i <= 100; i++) { const int N = i; // dont know how to do this A<N> a; a.functionCalls(); } } 这个怎么做?希望有一种方法可以做到这一点。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.