Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:52:21+00:00 2026-06-14T12:52:21+00:00

Perhaps i have two interfaces with same function names and parameters, but with different

  • 0

Perhaps i have two interfaces with same function names and parameters, but with different return values:

struct A { virtual void foo() = 0; };
struct B { virtual int foo() = 0; };

How to define class C, that inherits this interfaces (if it’s of course possible)?
For example i write some pseudocode that doesn’t compiled:

// this code is fake, it doesn't compiled!!
struct C : A, B
{
    // how to tell compiler what method using if referenced from C?
    using void foo();  // incorrect in VS 2012
    // and override A::foo() and B::foo()?
    virtual void foo() { std::cout << "void C::foo();\n"; } // incorrect
    virtual int foo() { std::cout << "int C::foo();\n"; return 0; } // incorrect
 }
 // ... for use in code
 C c;
 A &a = c;
 B &b = c;
 c.foo();     // call void C::foo() when reference from C instance
 a.foo();     // call void C::foo() when reference from A instance
 b.foo();     // call int C::foo() when reference from B instance
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:52:23+00:00Added an answer on June 14, 2026 at 12:52 pm

    It’s not possible, but not because of the multiple inheritance. Ambiguity arises due to invalid overload of foo in class C. You can’t have both int foo() and void foo() since return type is not part of function signature, thus the compiler won’t be able to resolve the calls to foo. You can look at your interface as a union of both A and B classes, so logically the problem is already present before the actual inheritance. Since from compiler perspective A and B are 2 distinct and unrelated types, there is no problem while compiling them and the error is delayed until point of actual unification in class C.

    See more here about function signatures and overloading: Is the return type part of the function signature?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes with identical implementations but different names. They are generated and
I have an ObjectDataSource (but perhaps this question is the same for all kinds
I have two web pages which work basically the same, code-wise, but one of
I have two functions that carry out the same functionality But has been implemented
I have a simple function that I'd like to test (perhaps mostly to appease
I have looked thoroughly, but I have not found the solution (or perhaps I
Perhaps it's a syntax error, but I never assume that. I have a -dead-
I have two lists old and new , with the same number of elements.
I have two tables. Table A has a list of employee names. Table B
I have actually two questions but they are kind of related so here they

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.