请问有人能为我解释一下吗?我了解宏和模板,但是我不知道作者表达的意思。这个定义的使用目的是什么?为什么要这样写?我们在这里定义了什么?如何以及为什么使用这个东西?
#define MY_CLASS(RET_TYPE, ... )\
template<typename Derived>\
__VA_ARGS__\
RET_TYPE my_class_impl<Derived>
我还有类似这样的东西
MY_CLASS( )::my_class_impl( int arg_id )
我也看到了。
template<typename Derived>
class my_class_impl
我从同事那里听说这是CRTP(奇特递归模板模式)的一个案例,但他没有更具体的见解。
此外,在后续中,我看到它被使用如下:
MY_CLASS(some_type)::find_desired_val(int x) {
// some code
}
所以,宏被用于在实际实现方法签名时替换类
my_class_impl
的签名?
my_class_impl
是什么? - Caninonostypename Derived
看起来像是一个 CRTP 嵌套在宏中。对于RET_TYPE
和...
,有哪些合理的参数可以提供,以及为什么在没有任何参数的情况下调用该宏,我不知道。 - Quentin__decltype(dllexport)
,但这是MSVC++的扩展。 - MSalters