Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is no problem with overloading or inheritance:</p> <pre><code>#include &lt;iostream&gt; #include &lt;memory&gt; namespace { struct A { virtual void f() { std::cout&lt;&lt;"inside A's f()\n"; } template &lt;typename T&gt; void f(T t) { std::cout&lt;&lt;T::i&lt;&lt;'\t'; this-&gt;f(); } }; struct B : A { void f() { std::cout&lt;&lt;"hello\t"; A::f(); } }; struct C { static const unsigned int i = 5; }; struct D { enum { i = 6 }; }; } int main() { std::auto_ptr&lt;A&gt; b(new B()); b-&gt;f(C()); b-&gt;f(D()); } </code></pre> <p>Works correctly. On the other hand, the smallest example I can find that exhibits your problem does not have inheritance or overloading:</p> <pre><code>#include &lt;iostream&gt; namespace { struct A { template&lt;class C&gt; void print(C c) { c.print(); } }; } int main() { struct B { void print() { std::cout &lt;&lt; "whee!\n"; } }; A a; B b; a.print(b); } </code></pre> <p>Note that if <code>struct B</code> is defined in a namespace (whether it's an unnamed namespace, or a completely different namespace, or the global namespace) instead of inside <code>main()</code> that this compiles without error.</p> <p><strike>I don't know enough of the standard to say if this is a bug, but it appears to be one. I've gone ahead and <a href="http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39770" rel="nofollow noreferrer">reported it to the GCC bug database</a>.</strike></p> <hr> <p>And here's your answer from the GCC developers (from the link above): "Local classes cannot be template arguments."</p> <p>So the code is broken. <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1427.pdf" rel="nofollow noreferrer">Not that it's a bad idea</a>. In fact, C++0x removes this restriction.</p> <p>I noticed the line</p> <blockquote> <p>Note that the code works in GCC if I explicitly cast vpc to (RenFlexibleVertexPc *)</p> </blockquote> <p>And since <code>RenFlexibleVertexPc</code> is not a local class this makes sense. However <code>Pc</code> is a local class/struct, so it is not allowed.</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