示例代码:
//This uses the shortcode funtion, but doesn't gives the gallery ID
register_block_type( 'cgb/block-rb-scroll-gallery-block', array(
'render_callback' => 'rb_scroll_gallery_shortcode',
) );
尝试编译它会出现以下错误:
#include <variant>
template<typename T>
std::variant<int, T> f(bool select, int v1, T v2)
{
std::variant<int, T> v;
if (select == false)
v.emplace<int>(v1);
else
v.emplace<T>(v2);
return v;
}
int main()
{
auto v = f<float>(true, 1, 2.0f);
}
我该如何解决这种使用情况,在这种情况下我需要在函数模板(实际上是类模板的成员函数,但问题相同)中使用$ g++ -std=gnu++17 variant.cpp
variant.cpp: In function ‘std::variant<int, T> f(bool, int, T)’:
variant.cpp:8:13: error: expected primary-expression before ‘int’
v.emplace<int>(v1);
^~~
variant.cpp:8:13: error: expected ‘;’ before ‘int’
v.emplace<int>(v1);
^~~
;
variant.cpp:10:14: error: expected primary-expression before ‘>’ token
v.emplace<T>(v2);
^
?将类型更改为索引(std::variant
-> emplace<int>
,emplace<0>
-> emplace<T>
)并没有帮助,因为那时GCC似乎认为我想将函数与整数进行比较:
emplace<1>
这是错误还是功能?