title: how to store values of type <T>
body: <p>How to store values of datatype <code>&lt;T&gt;</code>? What I'm trying to do is to have a function that will work for <code>long</code> or <code>double</code> types. For example, to return median of 5 numbers (because now I have two classes, one for long, one for double). Two things I do not know how to:</p>
  
  <ul>
  <li>how to store <code>&lt;T&gt;</code> values</li>
  <li>is it possible to call function with return type <code>&lt;T&gt;</code> from function of return type <code>&lt;T&gt;</code></li>
  </ul>
  
  <p>This is non/working code, stripped to be readable. The code is for Arduino (or other similar microcontrolers). Thank you.</p>
  
  <pre><code>//how to store custom type?
  //in practice, this may be a single value, array,
  //or struct with one of the members being T
  
  T values[5]={2,6,8,9,11};
  
  //public
  template &lt;typename T&gt; T getFirst (){
    T result = getPos[0]; 
    return result;  
  }
  
  //private
  template &lt;typename T&gt; T getPos (byte index){
    T result = values[index]; 
    return result;  
  }
  
  void setup() {
    // put your setup code here, to run once:
    double k;
    k=getFirst()
  }
  
  void loop() {
    // put your main code here, to run repeatedly:
  
  }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 4,</strong> THE FINAL THOUGHTS:
  Since some users reported too many edits, I've decided to delete all of it. I've left only the original question. I will give my final findings in a new, separate anwser.</p>