相关疑难解决方法(0)

编译时断言?

有没有办法可以断言两个常量表达式在编译时是相等的?

例如,我希望这会导致编译时错误

enum { foo=263, bar=264 };
SOME_EXPRESSION(foo,bar)
Run Code Online (Sandbox Code Playgroud)

但我希望这不会导致错误

enum { foo=263, bar=263 };
SOME_EXPRESSION(foo,bar)
Run Code Online (Sandbox Code Playgroud)

编辑:上面简化了.我的情况更像是

some_other_file_I_dont_control.h:

class X
{
public:
   enum { foo=263 };
}
Run Code Online (Sandbox Code Playgroud)

my_file.h:

enum { bar=something+somethingelse }; // bar should equal X::foo
SOME_EXPRESSION(X::foo, bar)
Run Code Online (Sandbox Code Playgroud)

c++ compiler-construction

33
推荐指数
5
解决办法
4万
查看次数

标签 统计

c++ ×1

compiler-construction ×1