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 7704403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:40:22+00:00 2026-05-31T23:40:22+00:00

class C1 { void A(); void B(); } void C1::A(){ return B(); } class

  • 0
class C1 {
    void A();
    void B();
}

void C1::A(){ return B(); }

class C2 : public C1 {
    void B();
}

C2 *obj = new C2;
obj->A(); // returns B() from C1

Why does B() from C1 called? How to make A() exist only in C1 and call B() from C2?

  • 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-05-31T23:40:23+00:00Added an answer on May 31, 2026 at 11:40 pm

    You need to make B() in C1 a virtual function.

    Virtual functions are basically function pointers that take their value upon initialization of the object. If you new C1, the function pointer would point to C1::B while if you new C2 that function pointer would point to C2::B.

    Note: To read more about virtual and related subjects, search for function overriding and polymorphism.

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

Sidebar

Related Questions

Class parent { protected void myMethod() { if(someCodition) { //return this as well as
class test <T> where T : class { public void Write<T>() { Console.Write(typeof(T).FullName); }
How would I do this (C#) in F# public class MyClass { void Render(TextWriter
I have the following two classes, one inherits from the other Class A{ void
class foo { public: void say_type_name() { std::cout << typeid(this).name() << std::endl; } };
class B{ private: void DoSomething(); } class W{ private: class D: public B{ }
Consider the following code: public abstract class Base { public void getAnswer(); } public
I have the following method: class MyClass { public: MyClass; bool method (MyClass &obj);
class A { void F() { System.out.println(a); }} class B extends A { void
Consider the following code: class Base { void f() { } }; class Derived:

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.