这是我正在尝试做的简化版本
enum First
{
a,
b,
c,
nbElementFirstEnum,
};
enum Second
{
a,
b,
c,
nbElementSecondEnum,
};
static_assert(
First::nbElementFirstEnum == Second::nbElementSecondEnum,
"Not the same number of element in the enums.");
/*static_assert(
First::nbElementFirstEnum == Second::nbElementSecondEnum,
"Not the same number of element in the enums." + First::nbElementFirstEnum + " " + Second::nbElementSecondEnum);*/
Run Code Online (Sandbox Code Playgroud)
但是我希望能够在断言消息中打印First :: nbElementFirstEnum和Second :: nbElementSecondEnum的值(就像在注释版本中显然不起作用).我尝试使用"#"进行宏连接.我还尝试使用可变参数模板,使用%10检索每个数字并将"0"字符添加到检索到的值,但我得到的只是constexpr char [].
所以我的问题是如何让我的枚举值以字符串文字打印.
可能重复:
最有趣的话题是: 在编译时打印sizeof(T) 但是我不希望有警告或退出代码来知道值.
嗨,我正在尝试使我的代码在clang 3.2-9下编译,这是我无法编译的简化示例:
template<template <class>class Derived, typename Type>
class Foo
{
public:
Foo(){}
};
template<typename Type>
class Bar
: public Foo<Bar, Type>
{
public:
Bar()
: Foo<Bar, Type>()
{}
};
int main()
{
Bar<int> toto;
}
Run Code Online (Sandbox Code Playgroud)
这是clang告诉我的错误:
test.cpp:14:19: error: template argument for template template parameter must be a class template
: Foo<Bar, Type>()
^
test.cpp:14:15: error: expected class member or base class name
: Foo<Bar, Type>()
^
test.cpp:14:15: error: expected '{' or ','
3 errors generated.
Run Code Online (Sandbox Code Playgroud)
它在gcc 4.7.2下编译没有任何问题.我无法使用正确的语法使其在clang下工作.请有人帮帮我,我有点卡住了......