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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:35:26+00:00 2026-06-10T02:35:26+00:00

Consider: struct foo { void foobar(){} }; struct bar : protected foo { using

  • 0

Consider:

struct foo
{
    void foobar(){}
};

struct bar : protected foo
{
    using foo::foobar;
};

int main()
{
    bar b;
    b.foobar(); // Fine
    &bar::foobar; // Not fine
}

I’m wondering what the rationale for letting using declarations expose the member, but not a pointer to it. In fact it would seem all using declarations that changes access level works for everything except taking the address of an exposed function.

UPDATE: An example which resembles my real use case better:

#include "boost/bind.hpp"

struct foo
{
    void foobar() {}
};

struct bar : protected foo
{
    using foo::foobar;
    bar() { boost::bind( &bar::foobar, this )(); } // Crashes VS2008, GCC 4.1.1 fails to compile as it tries to go through foo*
};

int main()
{
    bar b;
}

However, Mike Seymours’ explanation is spot on and explains why GCC fails. Thanks!

  • 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-10T02:35:27+00:00Added an answer on June 10, 2026 at 2:35 am

    [I am assuming that in your program the code is: void (bar::*p)() = &bar::foobar;]

    The problem is not that the using declaration does not bring the identifier into space, but the semantics of &bar::foobar. I am considering (I would have done it if I had the time) refilling a Defect Report with this. There is already one such report.

    Basically the problem is that the using declaration brings the base function into scope for lookup in the derived type, and the access specifiers for the expression &bar::foobar will be checked against bar. But, the result of the expression &bar::foobar is of type void (foo::*)(), not void (bar::*)(). Now, after evaluation of &bar::foobar if you try to use that as a void (bar::*)() the compiler will try to perform the conversion of the pointer to member but will fail because foo is a protected base of bar, and in the context of main you don’t have access to that relationship.

    Note that I consider that to be a defect in the language for two reasons: first it breaks your code: void (bar::*p)() = &bar::foobar; surprisingly fails to compile. Secondly, it breaks access protections in other cases:

    class base {
    protected: void f() {}
    };
    struct derived : base {
       void foo( base& b ) {
           b.f();                // Error
           b.*(&derived::f)();   // OK
       }
    };
    

    This problem is actually symmetric to yours, while in yours the surprising type of the address-of-member operation inhibits your use case when it shouldn’t, in this case it allows an usage that is against the intent of protected.

    Related links:

    • DR 203 – Type of address-of-member expression
    • DR 1007 – Protected access and pointers to members

    After the comment on using bind, it might not be the case that you are trying to convert the pointer to member to a pointer to member of bar directly, but somewhere inside bind code will be generated to apply the pointer to member to an instance of bar, and that requires the conversion.

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

Sidebar

Related Questions

Consider the following: struct Foo { char c; int i; }; void Bar(void) {
Consider the following code: #include <vector> using namespace std; struct foo { void bar()
Consider the following code: #include <iostream> struct foo { // (a): void bar() {
Consider the following code: struct Foo { mutable int m; template<int Foo::* member> void
Consider the following code: struct Foo { }; struct Bar { explicit Bar(const Foo&)
Consider: struct foo { int a; int b; }; void* p = (void*)malloc(sizeof(struct foo));
Consider the following code: struct Foo { Foo operator+(const Foo &rhs) const; // notice
Consider something like: struct Parameter { int a; Parameter(){a = 0;} void setA(int newA){a
Consider the following small example: template<typename T> void foo(T a) { ... } struct
Consider this smallest example (I could think of): struct Bar; struct Foo { Bar*

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.