Note that there are some explanatory texts on larger screens.

plurals
  1. POTemplate Return Types / Cast as function of Template
    text
    copied!<p>I'm working with some generated classes with broken polymorphism. For every generated class T, there are a handful of T_type_info, T_writer, T_reader classes which are only related to T conceptually. </p> <p>What I'm trying to do is something like this:</p> <pre><code>template &lt;class T&gt; class Wrapper { public: template &lt;class W&gt; W topic_cast(BrokenBaseClassWriter* p); // other operations with the same problem ... }; template &lt;&gt; class Wrapper&lt;MyTopic&gt; { public: template &lt;&gt; MyTopicWriter* topic_cast(BrokenBaseClassWriter* p) { ... } }; </code></pre> <p>So that I can do things like:</p> <pre><code>void Write(const Wrapper&lt;T&gt;&amp; topic) { BrokenBaseClassWriter p = not_important; topic.topic_cast(p)-&gt;do_stuff(); } </code></pre> <p>My T classes are generated from an IDL and are concepts that exist in application space. They don't derive from anything. In my example above, W is not really an independent parameter, it's "Something Not T that depends on T". I'm trying to keep all knowledge of T in the app, and all knowledge of T' (without knowing about T) in the backend.</p> <p>The compiler however says my topic_cast function is not a template function - I think because the template occurs in the return type and it wouldn't be distinguishable from any other instantiations. I know that that (templates differ only by return type) is not legal. Only in my case it really would be unique because W is not an independent parameter. But arguing with the compiler is seldom helpful.</p> <p>Can I do this, or is there another way to do this "cast as function of template type"?</p>
 

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