【发布时间】:2017-04-11 11:17:23
【问题描述】:
我的尝试是:
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 MSVC 不执行两阶段查找,这也是它在那里工作正常的部分原因。不是编译器错误。
标签: c++ templates inheritance crtp