Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A possible solution:</p> <pre><code>#include &lt;iostream&gt; #include &lt;type_traits&gt; class A { public: //... static const char fooString[]; }; const char A::fooString[] = "This is a Foo."; class B { public: //... static const char barString[]; }; const char B::barString[] = "This is a Bar."; class C { public: //... static const char fooString[]; }; const char C::fooString[] = "This is also a Foo."; void doFoo(const char*s) { std::cout &lt;&lt; "doFoo: " &lt;&lt; s &lt;&lt; "\n"; } void doBar(const char*s) { std::cout &lt;&lt; "doBar: " &lt;&lt; s &lt;&lt; "\n"; } template&lt;class T&gt; class Something { public: //This version should be called if T has a static member called "fooString", //so it should be called if T is either class A or C template &lt;typename TT = T, typename std::enable_if&lt;TT::fooString != 0, bool&gt;::type = false&gt; void doSomething() { doFoo(T::fooString); } //This version should be called if T has a static member called "barString", //so it should be called if T is class B template &lt;typename TT = T, typename std::enable_if&lt;TT::barString != 0, bool&gt;::type = false&gt; void doSomething() { doBar(T::barString); } }; int main() { Something&lt;A&gt; a; Something&lt;B&gt; b; Something&lt;C&gt; c; a.doSomething(); //should call doFoo(A::fooString) b.doSomething(); //should call doBar(B::barString) c.doSomething(); //should call doFoo(C::fooString) } </code></pre> <p>Output:</p> <pre><code>doFoo: This is a Foo. doBar: This is a Bar. doFoo: This is also a Foo. </code></pre>
 

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