Note that there are some explanatory texts on larger screens.

plurals
  1. POSegfaulting calling a function
    text
    copied!<p>I have the following class heirarchy:</p> <pre><code>ICSL::ISystemModel ICSL::ISystemModelAffine : public ISystemModel ICSL::Quadrotor::SystemModelQuadrotor : public QObject, ISystemModelAffine ICSL::Quadrotor::SystemModelQuadrotorSimulated : public public SystemModelQuadrotor </code></pre> <p>Then, in the another class I define</p> <pre><code>SystemModelQuadrotor mDynamicModelReal; SystemModelQuadrotorSimulated mDynamicModelSimulated; </code></pre> <p>During the initialization I call a bunch of functions to set variables on both <code>mDynamicModelReal</code> and <code>mDynamicModelSimulated</code> with no problems. Later on I call some functions from <code>ISystemModel</code> to access some variables which works fine for <code>mDynamicModelReal</code> but segfaults for <code>mDynamicModelSimulated</code>. Checking in gdb, the variable value is correct, and it seems to know what the function is, but it complains when trying to call the actual function (based on my limited understanding of these things). Here is gdb probing after it segfaulted for a call to <code>mDynamicModelSimulated.getName()</code></p> <pre><code>(gdb) print mDynamicModelSimulated.mName $19 = {static npos = &lt;optimized out&gt;, _M_dataplus = {&lt;std::allocator&lt;char&gt;&gt; = {&lt;__gnu_cxx::new_allocator&lt;char&gt;&gt; = {&lt;No data fields&gt;}, &lt;No data fields&gt;}, _M_p = 0x810658 "quadGaui5"}} (gdb) print mDynamicModelSimulated.getName $20 = {const std::string (ICSL::ISystemModel * const)} 0x44f506 &lt;ICSL::ISystemModel::getName()&gt; (gdb) print mDynamicModelSimulated.getName() Cannot access memory at address 0x4082c00000000030 </code></pre> <p>And here is the definition of getName()</p> <pre><code>Class ISystemModel { public: ... virtual std::string const getName(){return mName;}; ... protected: ... std::string mName; ... }; </code></pre> <p>I don't understand why it can't make that function call. I did discover that if I remove "<code>virtual</code>" from the function definition it doesn't segfault but I don't see why that makes a difference. Where should I be looking for the source of the problem?</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