를 사용하는 경우 컴파일러는 기본 클래스의 메서드를 참조하지 않는 이유는 다음 코드 조각이 :CRTP
struct Iface
{
virtual int Read() = 0;
int Read(int x) {
return Read() + x;
}
};
template <typename Impl>
struct Crtp : public Iface
{
virtual int Read() {
return static_cast<Impl&>(*this).ReadImpl();
}
//using Iface::Read;
};
struct IfaceImpl : public Crtp<IfaceImpl>
{
int ReadImpl() {
return 42;
}
};
int main()
{
IfaceImpl impl;
impl.Read(24); // compilation error
Iface& iface = impl;
iface.Read(24); // always compiles successfully
}
두 MSVC, GCC와 그 소리가이 코드를 거부, 그들이 찾을 수없는 방법 Read(int x)
단을 using Iface::Read
에서 Crtp
을 주석 처리하면 코드가 성공적으로 컴파일됩니다. 내가 Iface는에 대한 참조를 수강하면이 Read(int x)
왜 이런 일이 않는 호출 할 수
는주?