1
我的嘗試是:如何在CRTP中調用派生的模板化函數?
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>();
~~~~~~~~~~~~~~~~~~~~^~~
編譯器錯誤? VS 2017工作正常 – Raxvan
@Raxvan MSVC不執行兩階段查找,這是部分原因在那裏工作的部分原因。不是編譯器錯誤。 – user975989