Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For reference, the following links seem related:</p> <ol> <li><a href="https://stackoverflow.com/questions/7319494/overloading-virtual-functions-of-the-same-name-from-different-base-classes-is-i?rq=1">Overloading virtual functions of the same name from different base classes. Is it possible?</a></li> <li><a href="https://stackoverflow.com/questions/3150310/c-virtual-override-functions-with-same-name">C++ virtual override functions with same name</a></li> <li><a href="https://stackoverflow.com/questions/14176916/derived-class-defines-function-via-base-class?rq=1">Derived class defines function via base class</a></li> </ol> <p>The OP in the second link asked if he could do something like you asked:</p> <pre><code>class Impl : public A , public B { public: void A::Function () { cout &lt;&lt; "A::Function" &lt;&lt; endl; } void B::Function () { cout &lt;&lt; "B::Function" &lt;&lt; endl; } }; </code></pre> <p>Johannes answer is:</p> <blockquote> <p>You cannot use qualified names there. I you write void Function() { ... } you are overriding both functions. Herb Sutter shows how it can be solved.</p> <p>Another option is to rename those functions, because apparently they do something different (otherwise i don't see the problem of overriding both with identical behavior).</p> </blockquote> <p>So one possible solution (by James Kanze from the first link) looks like this:</p> <pre><code>class RemapA : public A { virtual void fnInA() = 0; public: virtual void fn() { fnInA(); } }; class RemapB : public B { virtual int fnInB() = 0; public: virtual int fn() { return fnInB(); } }; class C : public RemapA, public RemapB { virtual void fnInA() { /* ... */ } virtual void fnInB() { /* ... */ } // ... }; </code></pre> <p>Herb Sutter's link essentially says the same thing.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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