Hello Thomas,<br><br>Function templates might work:<br>    <a href="http://www.cplusplus.com/doc/tutorial/templates">http://www.cplusplus.com/doc/tutorial/templates</a><br>although I have never tried using function pointers to template functions before...<br>

<br>/////////////////////////////////////////////////////////////<br><br>#include &lt;iostream&gt;<br><br>using namespace std;<br><br>// template class where all of the work will be done:<br>template&lt;class TYPE&gt;<br>

void printValue(TYPE value) {<br>   cout &lt;&lt; &quot;The value is &quot; &lt;&lt; value &lt;&lt; endl;<br>   cout &lt;&lt; &quot;The squared value is: &quot; &lt;&lt; value * value &lt;&lt; endl;<br>}<br><br>// create wrapper functions for each type needed:<br>

void intcallback(int value) { printValue&lt;int&gt;(value); }<br>void floatcallback(float value) { printValue&lt;float&gt;(value); }<br><br>// two example functions which require different type of callback function:<br>void intaction(void* funptr, int value) {<br>

   void(*action)(int val) = (void (*)(int))funptr;<br>   (*action)(value);<br>}<br><br>void floataction(void* funptr, float value) {<br>   void(*action)(float val) = (void (*)(float))funptr;<br>   (*action)(value);<br>}<br>

<br>// test run:<br>int main(void) {<br>   intaction((void*)&amp;intcallback, 55);<br>   floataction((void*)&amp;floatcallback, 2.4);<br>   return 0;<br>}<br><br>/* output after running program:<br><br>The value is 55<br>

The squared value is: 3025<br>The value is 2.4<br>The squared value is: 5.76<br><br>*/<br><br><br>/////////////////////////////////////////////////////////<br><br>#define pre-processor directives to create a macro might also work, but probably not very useful to creating a complicated function inside of a macro.  Couldn&#39;t be used directly as a callback function (would use a wrapper function as shown above).<br>

<br><br>////////////////////////////////////////<br><br>#include &lt;iostream&gt;<br><br>using namespace std;<br><br>#define printValue(type, value) {cout &lt;&lt; (type)value &lt;&lt; endl; }<br><br>int main(void) {<br>
   printValue(int, 5.5);<br>
   printValue(float, 5.5);<br>   return 0;<br>}<br><br>/* Output from program:<br><br>5<br>5.5<br><br>*/<br><br>//////////////////////////////////////<br><br>-=+Craig<br><br><br><div class="gmail_quote">On Fri, Sep 16, 2011 at 2:56 AM, TJF <span dir="ltr">&lt;<a href="mailto:tjfoerster@web.de">tjfoerster@web.de</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hi everybody,<br>
<br>
is there any idea how to make typedef of MY_TYPE variable (depending on<br>
&quot;oput&quot;) in the following example? If I use more copies of the Callback<br>
function it works (output_1, output_2,...). But is there any other way<br>
in C++ to make this smarter?<br>
<br>
It must be defined during runtime. Is it possible to define it global<br>
(MY_TYPE_1, MY_TYPE_2,...) and do ... after oput ?  I tried some ways<br>
with templates, but I didn&#39;t have success.<br>
<br>
______________________________________<br>
<br>
// Callback<br>
int output( void *outputBuffer, void *inputBuffer, ...)<br>
     {<br>
         typedef float MY_TYPE;<br>
         ...<br>
     }<br>
<br>
int main( int argc, char *argv[] )<br>
     {<br>
     ...// here it depends on oput what kind of MY_TYPE will be used<br>
         switch (oput)<br>
         {<br>
         case 1:<br>
             try<br>
             {<br>
                 openStream( ..., &amp;output, ... ); // i.e. output with<br>
callback function , typedef double MY_TYPE<br>
                 ...<br>
             }<br>
             break;<br>
         case 2:<br>
             ...<br>
     }<br>
______________________________________<br>
<br>
Best regards<br>
Thomas<br>
<br>
_______________________________________________<br>
Stk mailing list<br>
<a href="mailto:Stk@ccrma.stanford.edu">Stk@ccrma.stanford.edu</a><br>
<a href="http://ccrma-mail.stanford.edu/mailman/listinfo/stk" target="_blank">http://ccrma-mail.stanford.edu/mailman/listinfo/stk</a><br>
</blockquote></div><br>