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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:38:49+00:00 2026-06-16T03:38:49+00:00

class A { void methodToCall() {}; } class B { B() { subscribeToEvent(); }

  • 0
class A {
 void methodToCall() {};
}

class B {
 B() {
   subscribeToEvent();
 }
 void eventHandler(Event* E) {
   call A::methodToCall()
 }
}

class C : public A, public B{
}  

This may seem like a rare situation so let me explain what I’m trying to do.

I have alot of classes that are like class A. These are generated by another framework so I do not have control over how they are generated.

For every class A I have one or more class C‘s that inherit a class like A.

I have developed the need to call A::MethodToCall() when eventHandler() is called. My goal is not to have to subscribe and provide an eventhadler method in all of my classes like class C.

I would much rather create a one class B that all my class C’s can simply inherit.

My problem is I do not know how to make the call to class A from class B.

If there is a better way of doing this I’m open to it.

  • 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-16T03:38:50+00:00Added an answer on June 16, 2026 at 3:38 am

    Your code doesn’t match your description (in the code B does not inherit from A, whereas in your description it does), but I think what you’re saying is “I have a large number of classes like A, and a large number of classes that inherit from classes like A (C in your example), and there’s a bunch of common stuff in those subclasses I’d like to factor out (into B in your example), but it includes stuff that depends on the specific A (calling an A method in your example) and it defeats the whole point to have to make many B’s (one for each A) mostly all alike.”

    One thing you could use is the ‘template class inheriting from argument’ trick to define large numbers of B variants as a single template class:

    template<class A> B : public A {
        void eventHandler(Event* E) {
           call methodToCall(); 
        }
    }
    
    class C1 : public B<A1> {
         ... whatever
    
    class C2 : public B<A2> { ...
    

    If you have certain A classes that need slightly different stuff in B, you can also specialize the B template for those classes.

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

Sidebar

Related Questions

I have code like this: class Base { public: void operator = (const Base&
How would I do this (C#) in F# public class MyClass { void Render(TextWriter
When I call a the C++ function: public ref class TEST_CLASS { void TEST(void
I have a class which looks something like this: class MyClass { public: //
I have something like this in my unit test public class MyTestClass() { private
class test <T> where T : class { public void Write<T>() { Console.Write(typeof(T).FullName); }
class a{ public void foo(int a){ System.out.println(super); } } class b extends a{ public
Consider the following set of classes/Interfaces: class IFish{ public: virtual void eat() = 0;
For example: class Test { /// This var contain Apple class void* something; };
I'm having trouble with std::list and memory leaks: class AbstractObject { public: virtual void

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.