c++ - How do enable a function only if the class from which it is derived has a certain function? -
I am trying to write a function, let's call it base
Code> form as a template parameter and also the base class of derived
, which is a method if in derived
Defines a definite method that defines.
Here I have tried to apply it (feedback received from this question :)
#include & lt; Utility & gt; Struct GetValueImpl {template & lt; Typename T & gt; Fixed auto test (int) - & gt; Decltype (std :: declval & lt; t & gt; (). GetValue (0), std :: true_type {}); Template & lt; Typename ... & gt; Fixed std :: false_type test (...); }; Template & lt; Typename T & gt; Struct GetValueDefined: Public decltype (GetValueImpl :: Examiner & lt; T & gt; (0)) {}; Template & lt; Typename derived, int x & gt; Class base {public: // I want to define this function, if GetValue is defined in the derived template & lt; Typename ... Args & gt; Auto Test (const ergos and ...) - & gt; Typename std :: enable_if & lt; GetValueDefined & lt; Derived & gt; :: value & gt; :: type {}}; Template & lt; Std :: int32_t val & gt; Category Derived Example: Public Base & lt; DerivedExample & lt; Val & gt; 1 & gt; {Public: Template & lt; Typename T & gt; Int GetValue () {return 0;}}; Int main () {DerivedExample & lt; 1 & gt; D; D Test (1, 2); Return 0; }
This generates the following compiler error:
prog.cpp: 21: 10: error: 'std' in the name of 'type' No type:: enabled_if
.
Clearly my std :: enable_if
check is failing. but why?
The espionage system has to rely on names from the existing template. Use a default argument for derived
so that one (UN) can be successfully replaced:
template < Typename D = derived, typename ... Args & gt; Auto Test (const ergos and ...) - & gt; Typename std :: enable_if & lt; GetValueDefined & lt; D & gt; :: Price & gt; :: type {}
Comments
Post a Comment