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

  • Home
  • SEARCH
  • 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 8756217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:01:21+00:00 2026-06-13T14:01:21+00:00

In C++, I have a class FooA and a class FooB that both are

  • 0

In C++, I have a class FooA and a class FooB that both are child classes of a base class Foo. FooB has to implement interface Bar. If I only have a Foo pointer to a FooB and wish to use FooB’s Bar methods, I would have to do a cast. However, that seems to violate polymorphism.

I’m wondering if there’s a better approach to allow FooB to implement the Bar interface without forcing all Foo derived classes to also implement Bar.

  • 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-13T14:01:21+00:00Added an answer on June 13, 2026 at 2:01 pm

    Redesign your classes. Chances are inheritance isn’t what you need here.

    Rationale: If you have a Foo pointer somewhere, then its owner shouldn’t need to know whether it points to Foo object or FooB or any other derived object – it only uses Foo functionality, ignorant of the implementation. (That’s how polymorphism works in general.)

    In other words: If you have a Foo pointer and its user depends on functionality only in FooB, then that pointer should be of type FooB in the first place.

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

Sidebar

Related Questions

Say I have base class A. it has method void foo(A* a); It also
I have a class that extends a base class. The base class is more
Imagine that you have a list called List<Foo> . Foo is an abstract class,
In my use case I have a class with covariant type Foo[+T] and classes
I have class function Foo(a) { this.a = a; this.bar = function () {
Let's say I have this program: class Foo { public: unsigned int bar ()
I have class Foo. Foo has a property of public string x. I would
I have a Python class that has a class attribute set to something other
My question is so simple. Imagine we have a Foo class. and has a
Suppose I have an abstract class Bar that takes a type parameter: abstract class

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.