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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:15:17+00:00 2026-05-31T16:15:17+00:00

If I defined an interface in a base class and I’m calling that interface

  • 0

If I defined an interface in a base class and I’m calling that interface through a derived class, the only way that I found to use that base’s class interface is by using “using” in the derived class. I’m not sure if it’s a good practice. Here is a sample program

#include <memory>
#include <iostream>

using namespace std;

template <class T>
class B 
{
public:
  void outB() { cout << "dim from B is " << dim_ << endl ; }
  B(int dim) : dim_(dim) {}
  ~B() {}
protected:
  int dim_;
};

template <class T>
class A : B<T>
{
public:
  using B<T>::dim_;
  using B<T>::outB;
  void outA() { cout << "dim from A is " << dim_ << endl ; }
  A(int dim) : B<T>(dim) {}
  ~A() {}
private:
};


int main(int argc, const char *argv[])
{
  shared_ptr<A<double> > ap(new A<double>(2));
  ap->outA();
  ap->outB();
  return 0;
}

If I take away the line using B<T>::outB; the program does not compile. http://ideone.com/x6gm0

The problem with using using all the time is that if I have a long chain of derived classes (for example if I extensively use adapter pattern), I have to write using ...; in each derived class for all of inherited interfaces.

What is a good practice to go around the repetition of using in each derived class to keep the interfaces of the base class?

Note, i’d like to avoid using virtual. I need performance from the code.

  • 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-31T16:15:18+00:00Added an answer on May 31, 2026 at 4:15 pm

    Why not declaring class A: public B<T> in which case you wont need the using? Now this works out of the box for member functions in the base class. To get access to the base class member variables, you either need to do what you are doing or access them via explicit call to this pointer i.e this->dim_ instead of just dim_

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

Sidebar

Related Questions

I have a functional AdjacencyListGraph class that adheres to a defined interface GraphStructure. In
I have defined an interface in C++, i.e. a class containing only pure virtual
Currently I'm using a base class for some Customer model classes. As defined as
I have an abstract generic view-model that I use as a base-class for several
I am looking for a framework-defined interface that declares indexer. In other words, I
I have the interface defined as below and is implemented by a single class
I have the following interface defined to expose a .NET class to COM: [InterfaceType(ComInterfaceType.InterfaceIsDual)]
I have an NSWindow that I defined in interface builder. I want to make
I have an abstract immutable base class that defines enforces child classes to be
I have the following base abstract class defined as: public abstract class BaseObject<T> :

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.