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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:38:49+00:00 2026-05-15T03:38:49+00:00

Maybe even better is: Why does the standard require forwarding to a base class

  • 0

Maybe even better is: Why does the standard require forwarding to a base class in these situations? (yeah yeah yeah – Why? – Because.)

class B1 {
public:
    virtual void f()=0;
};
class B2 {
public:
    virtual void f(){}
};
class D : public B1,public B2{
};
class D2 : public B1,public B2{
public:
    using B2::f;
};
class D3 : public B1,public B2{
public:
    void f(){
        B2::f();
    }
};
D d;
D2 d2;
D3 d3;

MS gives:

sourceFile.cpp
sourceFile.cpp(24) : error C2259: 'D' : cannot instantiate abstract class
        due to following members:
        'void B1::f(void)' : is abstract
        sourceFile.cpp(6) : see declaration of 'B1::f'
sourceFile.cpp(25) : error C2259: 'D2' : cannot instantiate abstract class
        due to following members:
        'void B1::f(void)' : is abstract
        sourceFile.cpp(6) : see declaration of 'B

and similarly for the MS compiler.

I might buy the first case,D. But in D2 – f is unambiguously defined by the using declaration, why is that not enough for the compiler to be required to fill out the vtable?

Where in the standard is this situation defined?

added in reponse to answer

Regarding the answer below that I have accepted:

Why does this not seem an error in the spec? – If one has an inheritance hierarchy with a series of non virtual f()’s, the use of which in derived classes being determined by using statements, and one changes the decl of f in a base class to virtual then that can change which f is called in derived classes with using statements to pick their f. It is a c++ “gotcha”of which I was unaware. It may be part of the language but such “action at a distance” makes me uneasy and to me seems a violation of some sort of correctness / maintenance principle (that I can’t quite formulate right now).

But I can give an example:

#include <iostream>
using std::cout;


namespace NonVirtual_f{

class C0 {
public:
    void f(){cout<<"C0::f()"<<'\n';}
};

class C1 : public C0{
public:
    void f(){cout<<"C1::f()"<<'\n';}
};

class C2 : public virtual C1{
public:
    void f(){cout<<"C2::f()"<<'\n';}
};

class D3 : public virtual C1, public C2{
public:
    using C1::f;
};


}//namespace NonVirtual_f

namespace Virtual_f{


class C0 {
public:
    virtual void f(){cout<<"C0::f()"<<'\n';}
};

class C1 : public C0{
public:
    void f(){cout<<"C1::f()"<<'\n';}
};

class C2 : public virtual C1{
public:
    void f(){cout<<"C2::f()"<<'\n';}
};

class D3 : public virtual C1, public C2{
public:
    using C1::f;
};



}//namespace Virtual_f




int main(int argc,const char* const*argv){

    NonVirtual_f::D3 nv3;
    nv3.f();

    Virtual_f::D3 v3;
    v3.f();

    return 0;    
} 

Whence the output:

C1::f()
C2::f()

All that is changed is the virtualness of f in C0. In particular once the non-virtualness of f in a base class is chosen, it cannot be changed without maintenance issues if some derived class (that in general one can’t know about) has “overridden” as in the example immediately above.

If you counter with “Well, do not override that way in the NonVirtual case”, I agree it is bad practice but this seems more than just that. To me the language should:

not allow the using in NonVirtual::D3 (not possible currently as there may be other overloaded f’s to bring in [unless using allowed a signature in the function case])

or

disallow using statements of functions completely and force forwarding

or

have using actually override in all cases

or

allow some syntactical declarative for functions (essentially a function using) like:

void f(*signature*) = C2::f;

What, exactly, am I missing here?
Can someone come up with a scenario that clarifies the “why” of this choice in the standard?

  • 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-15T03:38:49+00:00Added an answer on May 15, 2026 at 3:38 am

    The C++ standard says in §10.3/2:

    The rules for member lookup (10.2) are used to determine the final overrider for a virtual function in the scope of a derived class but ignoring names introduced by using-declarations.

    So, even though you use using B2::f; to bring B2::f() into the derived class, it is not considered to override B1::f().

    Thus, D2 is abstract because of §10.4/4:

    A class is abstract if it contains or inherits at least one pure virtual function for which the final overrider is pure virtual.

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

Sidebar

Ask A Question

Stats

  • Questions 465k
  • Answers 465k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer try changing var eddx = friendsDB.Friends.Single(a => a.Id == id);… May 16, 2026 at 1:27 am
  • Editorial Team
    Editorial Team added an answer It's a simple text substitution macro. Works the same as… May 16, 2026 at 1:27 am
  • Editorial Team
    Editorial Team added an answer There is a fbml tag for that: fb:prompt-permission Example: <fb:prompt-permission… May 16, 2026 at 1:27 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.