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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:36:36+00:00 2026-05-25T01:36:36+00:00

I am using wxWidgets where, if you have ever used it, you will know

  • 0

I am using wxWidgets where, if you have ever used it, you will know that there are a lot of public functions in the base class. I recently ran into a situation where I would not want a method SetText() be called directly from the derived class. That is, the derived class inherited the SetText() function but I do not want this function to be available to clients. Instead, I am providing two new functions which call SetText() but not before some extra operations are performed.

Currently, the client (me!) can forget to call the special functions and simply call SetText(). Consequently, some extra operations will not be performed. These operations are subtle enough that it may be overlooked easily.

So, can I mark individual functions as private so that the client cannot possibly call them OR simply make it impossible for clients to call it directly (they will have to use my functions to call it indirectly)?

Note that SetText() is not virtual.

EDIT: To future programmers who stumble on this question, check both the marked answer and Doug T.’s answer.

  • 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-25T01:36:37+00:00Added an answer on May 25, 2026 at 1:36 am

    There are actually two ways of doing this. Doug T. gave a very good overview of the first one – using private/protected inheritance and composition – so I won’t go into that one.

    The problem with using private/protected inheritance is that it masks everything. Then, you have to selectively expose the members that you still want to be public. If you want most everything to remain public, and are only trying to mask out a single thing, then this can become a major headache. This gives rise to the need for the second way to do this – with the using keyword.

    For example, in your case, you could simply declare your class as follows:

    class Child : public Parent
    {
        //...
        private:
            using Parent::SetText; // overrides the access!
    };
    

    This only masks the SetText method!

    Just remember though, a pointer to a Child can always be cast to a pointer to a Parent, and access that method again becomes possible – but that’s a problem with inheritance, too:

    class Parent
    {
    public:
        void SomeMethod() { }
        void AnotherMethod() { }
    };
    
    class ChildUsing : public Parent
    {
    private:
        using Parent::SomeMethod;
    };
    
    class ChildPrivateInheritance : private Parent
    {
    };
    
    void main()
    {
        Parent *p = new Parent();
        ChildUsing *a = new ChildUsing();
        ChildPrivateInheritance *b = new ChildPrivateInheritance();
        p->SomeMethod();             // Works just fine
        a->SomeMethod();             //  !! Won't compile !!
        a->AnotherMethod();          // Works just fine
        ((Parent*)a)->SomeMethod();  // Compiles without a problem
        b->SomeMethod();             //  !! Won't compile !!
        b->AnotherMethod();          //  !! Won't compile !!
        ((Parent*)b)->SomeMethod();  // Again, compiles fine
    
        delete p; delete a; delete b;
    }
    

    Attempting to access SomeMethod on an instance of ChildUsing produces (in VS2005):

    error C2248: 'ChildUsing::SomeMethod' : cannot access private member declared in class 'ChildUsing'
    

    However, attempting to access either SomeMethod or AnotherMethod on an instance of ChildPrivateInheritance produces:

    error C2247: 'Parent::SomeMethod' not accessible because 'ChildPrivateInheritance' uses 'private' to inherit from 'Parent'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a program for my C++ programming class, using wxWidgets. I'm having
I have installed wxWidgets 2.9.3 on Ubuntu 10.10 using ../configure --with-gtk I am using
We have built an application using wxWidgets in C++ and use wxToolTips to provide
Have you ever attempted using Swing only to end up changing courses because it
I am using wxWidgets with c++. I have a wxTextCtrl in which the user
I am trying to make a Digital IC simulation using wxWidgets. I have decent
I have the following class definition: class IRenderable { public: virtual void Render( wxBitmap
I have a function that creates prompts using gtk.MessageDialog in PyGTK. How could I
I have tons of existing code using wxWidgets. The main window is wxDialog. Now
I have been using a few cross-platform GUI libraries (such as FLTK, wxWidgets, GTK++),

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.