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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T09:03:13+00:00 2026-05-14T09:03:13+00:00

When inheriting classes in C++ I understand members are inherited. But how does one

  • 0

When inheriting classes in C++ I understand members are inherited. But how does one inherit the methods as well?

For example, in the below code, I’d like the method “getValues” to be accessible not through just CPoly, but also by any class that inherits it. So one can call “getValues” on CRect directly.

class CPoly {
  private:
    int width, height;
  public:
    void getValues (int* a, int* b)
      { *a=width; *b=height;}
  };

class CRect: public CPoly {
  public:
    int area ()
      { return (width * height); }
  };

In other words, is there any way to inherit methods for simple generic methods like getters and setters?

  • 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-14T09:03:14+00:00Added an answer on May 14, 2026 at 9:03 am

    You can call getValues by using CRect, because getValues is inherited. The term “methods” is not defined by C++. If you refer to non-static member functions – they are members and are inherited to derived classes.

    Your error is not that getValues isn’t inherited, but that you try to access the inaccessible members width and height.

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

Sidebar

Related Questions

I know that when inheriting classes, you can also inherit Constructors example: class Book
I have questions about inheriting(extending) methods from classes and hiding some classes and methods
For 2 child template files inheriting a block, the {{ block.super }} does not
I'd like to find all the types inheriting from a base/interface. Anyone have a
Inside a DLL, we've defined two classes (Class1 and Class2) which inherit from an
When inheriting applications at a new job do you tend to stick to the
Say I am inheriting from a class with several overloaded constructors. By any chance
I created a Winforms AutoComplete combobox control inheriting from ComboBox with the following method:
If you use an WebHandler inheriting IHttpAsyncHandler, you shouldn't notice that under undetermined specific
In a custom role provider (inheriting from RoleProvider) in .NET 2.0, the IsUserInRole method

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.