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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:07:44+00:00 2026-05-24T19:07:44+00:00

Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)

  • 0

Suppose I have this class hierarchy:

class A {
public:
    virtual void foo(Base *b) = 0;
};

class B {
public:
    virtual void bar() = 0;
};


class C : public A, public B {
public:
    virtual void viz() = 0;
};

class E : public C {
public:
    /** Some non-pure virtual functions, does not implement foo */
};

class F : public E {
    /** does not implement foo */
}

class G : public E {
    /** does not implement foo */
}

Now, I would like to define derived, “templatized” versions of F and G, which declares a method foo(T *s) and where the implementation of foo(Base *s) simply calls foo(T *s) by applying a static_cast.

Moreover, I don’t wan to expose the template arguments to A, because users of these interfaces (A, B, C, E) should not be exposed to the template parameters (I’m writing a plugin architecture and user-types that derives a given interface are passed back and forth from plugins to base system).

What I thought was to define this class:

template <typename T>
class GA : public A{
...
}

and to define the “templatized” derivations of F and G like this:

template <typename T>
class GF : public F, public GA {
...
}

the problem is that GF sees two different declarations of foo() (one given by A, the other by GA), so the compiler throws me an error when I try to instantiate GF because foo(Base) is not defined.

How can I solve this?

  • 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-24T19:07:44+00:00Added an answer on May 24, 2026 at 7:07 pm

    I think the problem is that Impl inherits class A and class C inherits both Impl and A. This means there will be two instances of class A where first A’s foo is implemented by Impl and a seconds one is still pure virtual. Virtual inheritance can solve this problem, for example:

    class A {
    public:
        virtual void foo () = 0;
    };
    
    class Impl : virtual public A {
    public:
        virtual void foo () {}
    };
    
    class C
        : virtual public A
        , public Impl
    {
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose you have the following situation #include <iostream> class Animal { public: virtual void
Suppose I have the following class hierarchy: class A { int foo; virtual ~A()
Suppose I have this code class Base{ public: int getVal(); private: int a, b;
Suppose I have this code: class A { }; class B: virtual public A
Suppose I have code like this: template<class T, T initial_t> class Bar { //
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
Suppose I have some XAML like this: <Window.Resources> <v:MyClass x:Key=whatever Text=foo\nbar /> </Window.Resources> Obviously
Suppose we have the following class hierarchy: class Base { ... }; class Derived1
So suppose I have a tree class like this in c++ class Node{ void
Suppose I have this code (pseudocode) class SomeClass { class Person { public static

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.