#include <iostream>
using namespace std;
template <typename T, typename U>
struct BaseS
{
virtual unsigned int operator()(T t, U u) const;
};
template <typename T, typename U>
struct S : BaseS<T,U>
{
unsigned int operator()(T t, U u) const override
{
return 1;
}
};
template <typename T>
struct S<T,nullptr_t> : BaseS<T,nullptr_t>
{
virtual bool operator()(T t, nullptr_t u) const override
{
return 2;
}
};
class A{};
class B{};
int main() {
A a;
B b;
cout << S<A*,B*>()(&a,&b) << endl;
cout << S<A*,nullptr_t>()(&a,nullptr) << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGUgPHR5cGVuYW1lIFQsIHR5cGVuYW1lIFU+CnN0cnVjdCBCYXNlUwp7Cgl2aXJ0dWFsIHVuc2lnbmVkIGludCBvcGVyYXRvcigpKFQgdCwgVSB1KSBjb25zdDsKfTsKCnRlbXBsYXRlIDx0eXBlbmFtZSBULCB0eXBlbmFtZSBVPgpzdHJ1Y3QgUyA6IEJhc2VTPFQsVT4KewoJdW5zaWduZWQgaW50IG9wZXJhdG9yKCkoVCB0LCBVIHUpIGNvbnN0IG92ZXJyaWRlCgl7CgkJcmV0dXJuIDE7Cgl9Cn07Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4Kc3RydWN0IFM8VCxudWxscHRyX3Q+IDogQmFzZVM8VCxudWxscHRyX3Q+CnsKCXZpcnR1YWwgYm9vbCBvcGVyYXRvcigpKFQgdCwgbnVsbHB0cl90IHUpIGNvbnN0IG92ZXJyaWRlCgl7CgkJcmV0dXJuIDI7Cgl9Cn07CgpjbGFzcyBBe307CmNsYXNzIEJ7fTsKCmludCBtYWluKCkgewoJQSBhOwoJQiBiOwoJCgljb3V0IDw8IFM8QSosQio+KCkoJmEsJmIpIDw8IGVuZGw7Cgljb3V0IDw8IFM8QSosbnVsbHB0cl90PigpKCZhLG51bGxwdHIpIDw8IGVuZGw7CgkKCXJldHVybiAwOwp9Cg==
prog.cpp: In instantiation of ‘struct S<A*, std::nullptr_t>’:
prog.cpp:36:26: required from here
prog.cpp:22:15: error: conflicting return type specified for ‘bool S<T, std::nullptr_t>::operator()(T, std::nullptr_t) const [with T = A*; std::nullptr_t = std::nullptr_t]’
virtual bool operator()(T t, nullptr_t u) const override
^~~~~~~~
prog.cpp:7:23: error: overriding ‘unsigned int BaseS<T, U>::operator()(T, U) const [with T = A*; U = std::nullptr_t]’
virtual unsigned int operator()(T t, U u) const;
^~~~~~~~