Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>thanks for the answers.. helped me a lot to understand the problem. In effect I posted some wrong code, because i was misunderstanding the real problem. Anyway, i think i partially solved my problem. Here's the code:</p> <pre><code> #include &lt;iostream&gt; `` using namespace std; class Other{ public: void foo(){ cout &lt;&lt; "Other\n"; } void foo(int a){} }; class Abstract : public Other{ public: virtual void foo() {}; virtual void foo(int c){ Other::foo(c); } }; class A : public Abstract{ public: void foo(){ cout &lt;&lt; "A\n"; } }; class B : public Abstract{ public: void foo(){ cout &lt;&lt; "B\n"; } }; int main(){ cout &lt;&lt; "main\n"; Abstract * ptrA = new A(); Abstract * ptrB = new B(); Other *o = new Other(); o-&gt;foo(); ptrA-&gt;foo(); ptrB-&gt;foo(); ptrB-&gt;foo(3); //can't no more use the method foo with different signatures implemented in the base class Other, unless I explicitly redefined in the class Abstract dynamic_cast&lt;Other*&gt;(ptrB)-&gt;foo(3);//can't dynamic_cast from derived to base </code></pre> <p>I was making two errors:</p> <ol> <li><p>In my real code (not the simplified version posted before) i forgot to declare virtual the function foo()</p></li> <li><p>Even declaring virtual wasn't enough. In fact all the implementations of that function must be wrapped inside the class Abstract to become visible to the subclasses A and b. Otherwise wont't compile.</p></li> </ol> <p>I don't know if it could be a clean solution..in fact that way I need to wrap all foo method signatures. </p>
    singulars
    1. This table or related slice is empty.
    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.
    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