C ++ Templates and Derived Classes

I am trying to understand the following code. Derived is a derived structure from T and that means "," and then "Fallback" {}

template <class T> struct has_FlowTraits<T, true> { struct Fallback { bool flow; }; struct Derived : T, Fallback { }; //What does it means ? template<typename C> static char (&f(SameType<bool Fallback::*, &C::flow>*))[1]; template<typename C> static char (&f(...))[2]; public: static bool const value = sizeof(f<Derived>(0)) == 2; }; 
+6
source share
4 answers

This is the implementation of the participant identifier identifier . It uses SFINAE to check if type T has an element named flow .

Edit: The comma part you are asking for is multiple inheritance . Struct Derived (publicly) inherits from both T and Fallback.

+6
source

This is just multiple inheritance. The following is Derived , which is derived from T (and does not give a further definition):

 struct Derived : T { }; 

And the following: Derived , which derives from both T and Fallback :

 struct Derived : T, Fallback { }; 

That is, Derived inherits T members and Fallback members. In this case, since Derived is a structure, inheritance is generally accepted by default.

+2
source

A comma means that it is displayed either publicly or privately (depending on whether T or Fallback structure or class) from these two classes. This comma just includes those classes that will be derived from Derive .

+1
source

It means:

inside the has_FlowTraits struct definition, you also define a new struct called Derived .

You say that this Derived structure inherits type T and type Fallback . (If you look at the line before, struct Fallback just been defined).

the {} just means that there are no more implementation details. This type no longer requires a method or attribute definition.

+1
source

All Articles