Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy might my virtual function call be failing?
    text
    copied!<blockquote> <p><strong>Update:</strong> This issue is caused by bad memory usage, see <strong>solution</strong> at the bottom.</p> </blockquote> <p>Here's some semi-pseudo code:</p> <pre><code>class ClassA { public: virtual void VirtualFunction(); void SomeFunction(); } class ClassB : public ClassA { public: void VirtualFunction(); } void ClassA::VirtualFunction() { // Intentionally empty (code smell?). } void ClassA::SomeFunction() { VirtualFunction(); } void ClassB::VirtualFunction() { // I'd like this to be called from ClassA::SomeFunction() std::cout &lt;&lt; "Hello world!" &lt;&lt; endl; } </code></pre> <p><s>The C# equivalent is as follows:</s> Removed C# example, as it's not relevant to the actual problem.</p> <p>Why isn't the <code>ClassB::VirtualFunction</code> function being called when called from <code>ClassA::SomeFunction</code>? Instead <code>ClassA::VirtualFunction</code> is being called...</p> <p>When I <a href="https://stackoverflow.com/questions/738204/why-might-my-virtual-function-call-be-failing/738223#738223">force implementation of the virtual function</a> ClassA::VirtualFunction, like so:</p> <pre><code>class ClassA { public: virtual void VirtualFunction() = 0; void SomeFunction(); } class ClassB : public ClassA { public: void VirtualFunction(); } void ClassA::SomeFunction() { VirtualFunction(); } void ClassB::VirtualFunction() { // I'd like this to be called from ClassA::SomeFunction() std::cout &lt;&lt; "Hello world!" &lt;&lt; endl; } </code></pre> <p>The following error occurs at runtime, despite the derrived function deffinately being declared and defined.</p> <pre><code>pure virtual method called terminate called without an active exception </code></pre> <p><em>Note:</em> It seems like the error can be caused even by bad memory usage. See self-answer for details.</p> <h3>Update 1 - 4:</h3> <p><em>Comments removed (not releavnt).</em></p> <h3>Solution:</h3> <p><a href="https://stackoverflow.com/questions/738204/why-might-my-virtual-function-call-be-failing/738566#738566">Posted as an answer.</a></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