Note that there are some explanatory texts on larger screens.

plurals
  1. POstd::is_base_of() depth
    primarykey
    data
    text
    <p>I have a such hierarchy:</p> <pre><code>namespace MyService{ class IBase { public: virtual ~IBase(){} protected: IPointer *_somePointer; }; } </code></pre> <p><br /></p> <pre><code>class IInterface: public MyService::IBase { public: virtual ~IInterface(){} virtual std::string get() const = 0; }; </code></pre> <p><br /> </p> <pre><code>class ConcreteClass: public IInterface { public: std::string get() const { bool isNull = (_somePointer == NULL); return "Hello"; } }; </code></pre> <p><br /></p> <pre><code>bool isBase = std::is_base_of&lt;IBase, ConcreteClass&gt;::value; </code></pre> <p>I need to check is I3 is derived from I1. But std::is_base_of() doesn't work well for me - it return false. The goal is to add to any class IBase and check any class is there IBase in it hierarchy</p> <p>Found the problem, but not solution. My code is:</p> <pre><code>template&lt;class Base, class Derived&gt; bool IsDerivedFromBase() { if( std::tr1::is_fundamental&lt;Base&gt;::value ) throw MyService::Exceptions::ETypeTraitsInvalidArgument( "Base class can't be POD" ); if( std::tr1::is_fundamental&lt;Derived&gt;::value ) throw MyService::Exceptions::ETypeTraitsInvalidArgument( "Derived class can't be POD" ); bool a = std::tr1::is_base_of&lt;Base, Derived&gt;::value; return a; } </code></pre> <p>and i have a such</p> <pre><code>bool a = std::is_base_of&lt;MyService::IBase, SomeInterface&gt;::value; // true a = IsDerivedFromBase&lt;MyService::IBase, SomeInterface&gt;(); // false </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload