Note that there are some explanatory texts on larger screens.

plurals
  1. POMember function type for template specialization
    primarykey
    data
    text
    <p>I am studying the uses of function types in template specialization and I am wondering if there such a thing as a member function type (not talking about member function pointers).</p> <p>The case that led me to this question is better explained by an exemple...</p> <pre><code>template&lt; typename FunctionType &gt; struct Function; // Undefined // Specialize for functions with 0 parameter... template&lt; typename ReturnType &gt; struct Function&lt; ReturnType() &gt; // Notice the unusual syntax here... { // Function pointer that fits the signature of the template... ReturnType (*m_pointerToFunction)(); }; // Specialize for functions with 1 parameter... template&lt; typename ReturnType, typename ParameterType &gt; struct Function&lt; ReturnType(ParameterType) &gt; { ReturnType (*m_pointerToFunction)(ParameterType); }; // ... etc up to a certain number of parameter. // To use this template: void SomeFunctionTakingNoParameter() { } Function&lt; void() &gt; test; test.m_pointerToFunction = SomeFunctionTakingNoParameter; </code></pre> <p>Now what I would like to do is create specialization for member functions. The first thing I tried is:</p> <pre><code>template&lt; typename ReturnType, typename ObjectType, typename ParameterType &gt; class Function&lt; ObjectType, ReturnType(ParameterType) &gt; { ReturnType (ObjectType::*m_memberFunctionPointer)(ParameterType); }; </code></pre> <p>and I use it like this:</p> <pre><code>struct Object { void DoSomething() { } }; Function&lt; Object, void() &gt; function; function.m_memberFunctionPointer = &amp;Object::DoSomething; </code></pre> <p>I have to supply 2 arguments to the template (the object type and the signature). I would like to see if there is a way to do it all in one parameter.</p> <p>The next bit does not compile but I wonder if there is something similar in the language?</p> <pre><code>template&lt; typename ObjectType, typename ReturnType &gt; struct Function&lt; ObjectType::ReturnType() &gt; { ReturnType (ObjectType::*m_memberFunctionPointer)(); }; Function&lt; Object::void() &gt; function; function.m_memberFunctionPointer = &amp;Object::DoSomething; </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