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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:20:29+00:00 2026-06-15T17:20:29+00:00

Suppose I have a base class foo class foo { virtual int get() const

  • 0

Suppose I have a base class foo

class foo {
    virtual int get() const = 0;
}

and maybe 20 sub-classes foo_1, foo_2 … inherited from foo and in the form of:

class foo_1 : public foo {
    int get() const { return 1; }
}
...
class foo_20 : public foo {
    int get() const { return 20; }
}

Suddenly life is not so easy! I have a class foo_21, which has to do this:

class foo_21 : public foo {
    int get() { member_ = false; return 0; }
    bool member_;
}

The problem is get is declared as const in the base class, and I have to change
something in the sub-class foo_21. How could I find a way to go around it?

  • 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-15T17:20:30+00:00Added an answer on June 15, 2026 at 5:20 pm

    Your base function isn’t virtual, which makes all this highly speculative. Your code should already be working as you posted it (though maybe not as you expect).

    You could use mutable members:

    class foo_21 : public foo
    {
        int get() const { member_ = false; return 0; }
        mutable bool member_;
    };
    

    It’s important that the mutable variable doesn’t affect the logical constness of your class. If it does, you should rework your design.

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

Sidebar

Related Questions

Suppose I have some code like this: class Base { public: virtual int Foo(int)
I have 2 classes: class Base { public: virtual int Foo(int n); virtual void
Suppose we have two classes: class Base { private: int x; public: void f();
Suppose I have the following class hierarchy: class A { int foo; virtual ~A()
Suppose we have: class Base { __forceinline virtual int A() {return 1;} } class
Suppose I have two classes a base class and an inherited class as follows:
Suppose I have this class hierarchy: class A { public: virtual void foo(Base *b)
Suppose you have a Java class hierarchy of about 30 classes, with a base
Suppose I have a base and derived class: class Base { public: virtual void
Suppose I have two versions of operator-> (overloaded on const) in a base class.

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.