gpt4 book ai didi

c++ - 如何在 CRTP 中调用派生模板函数?

转载 作者:行者123 更新时间:2023-11-30 03:32:44 25 4
gpt4 key购买 nike

<分区>

我的尝试是:

template<typename Derived>
struct Base
{
void A()
{
((Derived *)this)->B<42>();
}
};

struct Derived : Base<Derived>
{
template<int> void B() { }
};

( http://coliru.stacked-crooked.com/a/cb24dd811b562466 )

结果

main.cpp: In member function 'void Base<Derived>::A()':
main.cpp:6:34: error: expected primary-expression before ')' token
((Derived *)this)->B<42>();
^
main.cpp: In instantiation of 'void Base<Derived>::A() [with Derived = Derived]':
main.cpp:17:17: required from here
main.cpp:6:30: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator<'
((Derived *)this)->B<42>();
~~~~~~~~~~~~~~~~~~~~^~~

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com