Note that there are some explanatory texts on larger screens.

plurals
  1. PO"could not convert template argument" to its own type
    primarykey
    data
    text
    <p>I'm trying to make a type which can type-safely encapsulate arbitrary types. I got the idea in my head that this might be possible from this answer: <a href="https://stackoverflow.com/questions/4298408/5-years-later-is-there-something-better-than-the-fastest-possible-c-delegate/4300544#4300544">5 years later, is there something better than the &quot;Fastest Possible C++ Delegates&quot;?</a> So far I have only succeeded in moving the problem, but I ran into an error that I can't find the root of.</p> <p>The compiler seems to be telling me that it can't cast the value to the value's own type, which strikes me as bizarre.</p> <p>I am running Mac OS X 10.6 with llvm-gcc 4.2 (gcc 4.2.1 front-end).</p> <p>Suggestions of how to get rid of the void* or move it to a less consequential position are welcome, but this question isn't really about that.</p> <p>The error:</p> <pre><code>$ g++ main.cpp main.cpp: In static member function ‘static Stamp StampFactory&lt;T&gt;::make(T*) [with T = int]’: main.cpp:33: instantiated from ‘Stamp makeStamp(T*) [with T = int]’ main.cpp:39: instantiated from here main.cpp:26: error: could not convert template argument ‘t’ to ‘int*’ </code></pre> <p>The code:</p> <pre><code>typedef void (*VoidFunc)(void*); struct Stamp { Stamp(VoidFunc p) { this-&gt;press = p; } VoidFunc press; }; template&lt;typename T&gt; struct StampFactory { template&lt;T* rvalue&gt; struct Pattern { void operator()(void* lvalue) { *dynamic_cast&lt;T*&gt;(lvalue) = *rvalue; } }; static Stamp make(T* t) { return Stamp(Pattern&lt;t&gt;()); // 28 } }; template&lt;typename T&gt; Stamp makeStamp(T* t) { return StampFactory&lt;T&gt;::make(t); // 33 } int main(int argc, char** argv) { int i = 0; Stamp s = makeStamp(&amp;i); //39 } </code></pre>
    singulars
    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.
 

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