Following scenario:
template <typename Derived>
class TBase
{
public:
TBase() = default;
~TBase() = default;
bool foo() noexcept
{
static_assert(&Derived::foo != &TBase<Derived>::foo, "foo missing in derived class.");
return false; // dead-line
}
template <typename Bla>
bool bar(Bla bla) noexcept
{
static_assert(&Derived::bar!= &TBase<Derived>::bar, "foo missing in derived class.");
return false; // dead-line
}
};
class TDerived : public TBase<TDerived>
{
public:
TDerived () noexcept = default;
~TDerived () noexcept = default;
bool foo() noexcept
{
// do something
return false;
}
// bool bar(Bla bla) noexcept -> is not implemented
};
int main()
{
TDerived drvd;
drvd.bar(2);
return 0;
}
https://onlinegdb.com/BkU4IrTBL
I get the compiler-error (probably the compiler being not able to deduce the type):
Severity Code Description Project File Line Suppression State Error C2568 '!=': unable to resolve function overload
what I could do is deleting
template <typename PODType> bool protectData(PODType f_buf) noexcept = delete;
but I would like to - if possible - I would prefer the approach with the static_assert. How can I achieve this?
Aucun commentaire:
Enregistrer un commentaire