Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you use templates you need to know AT COMPILE TIME which type(s) you're using. That's just the nature of templates (templates look like code that's dynamic at runtime, but in reality it's just shorthand that tells the compiler what versions of the function to compile and include in the object code). Best case senario is something like this:</p> <pre><code>template &lt;class T&gt; void DoSomethingWithMyInterface(MyInterface&lt;T&gt; X) { //do something } ... switch (MyObject.GetTypeCode()) { case TYPE1: DoSomethingWithMyInterface&lt;type1&gt;(MyObject); break; case TYPE2: DoSomethingWithMyInterface&lt;type2&gt;(MyObject); break; case TYPE3: DoSomethingWithMyInterface&lt;type3&gt;(MyObject); break; case TYPE4: DoSomethingWithMyInterface&lt;type4&gt;(MyObject); break; } </code></pre> <p>I actually use this situation a lot. I write templated c++ code that does the processing for a dynamically typed language. That means that the top level language doesn't know the data types until run time, but I need to know them at compile time. So I create this "TypeSwitch" (I actually have a fancy reusable one). That looks at the datatypes at run time and then figures out which of the already compiled template functions to run. </p> <p>Note - that this requires me knowing all the types I'm going to support before hand (and I do) and the switch statement actually causes the compiler to generate all of the code that could ever be executed. Then at runtime the right one is selected.</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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