title: C++ making a console: binding a function
body: <p>I am currently working on creating a console in c++. I have created a class to help link variables and functions in code to variables and functions in the console.</p>
  
  <p>I currently have it set where if I have a variable in code, I can redefine it under the new class and it will be visible to the console. The variable in code still behaves the same as before. </p>
  
  <p>Example:</p>
  
  <p><code>float var = 1.0;</code></p>
  
  <p>can be redefined as</p>
  
  <p><code>ConsoleVar var("myVariable")&lt;float&gt; = 1.0;</code></p>
  
  <p>var is the variable name in the code and myVariable is the name that you use to access it in the terminal</p>
  
  <p>My question is:</p>
  
  <p>How can I bind a function, or more specifically, detect the number and type of the arguments.
  I know that I can template the <code>ConsoleVar</code> class to a <code>void *</code> type to store a function but is there a way for me to auto detect the return type, number of arguments and type of arguments? I am planning on shipping this in a library so I am going for ease of use. If this is possible, I would really like to know (I'll even do assembly if needed) otherwise I have some ideas on how to implement it.  </p>
  
  <p>EDIT: So I think that I have a solution but I have a question... Is it possible to pass a variable number of arguments to a function. Not like varargs.</p>
  
  <p>For instance: I recieve 3 args from the command line, now I execute the function </p>
  
  <p><code>func(arg[1], arg[2], arg[3])</code></p>
  
  <p>Is it possible to send a variable number of arguments?</p>