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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:48:23+00:00 2026-06-07T11:48:23+00:00

We have several classes where a call to a member function may change state

  • 0

We have several classes where a call to a member function may change state and sometimes not depending on a boolean with default value.

 A a;
 a.set( "foobar" );
 assert( a.changed() == true );

versus

 A a;
 a.set( "foobar", false );
 assert( a.changed() == false );

Please note that those member functions are virtual. I would favor to use an alias to better read code and make a private member function still allowing the old method and give only the wrappers to the public:

 a.silentlySet( "foobar" ) {
    a.set( "foobar", false );
 }

I guess this would be inlined then anyway. I know I could write enums and constants which would also improve readability: a.set( "foobar", SILENTLY ); but I don’t feel good with it, as the problem is of boolean nature (do or not). On the other side. However I would like to hear how you handle such a situation. (I assume I will get an “it depends” answer as I’ve certainly missed some crucial details) Live with it?

Those member functions are not very often called and used, but also not seldom. What I fear is that sometimes you may misinterpret a boolean as silent/not_silent-flag when this has another meaning.

An example where this could also be misleading:

if( b->getData( false ) && something_other )

this could be mixed up with b->getData() == false

  • 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-07T11:48:26+00:00Added an answer on June 7, 2026 at 11:48 am

    but I don’t feel good with [using an enum here], as the problem is of boolean nature (do or not)

    No, an enum is perfect for this, use it. FWIW, there’s another discussion about this case on CodeReview.

    That said, yes, the wrapper function will most likely be inlined. C++ is all about providing abstractions without runtime cost. Inlining function calls is a fundamental tool in this regard, so compilers use it where ever applicable.

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

Sidebar

Related Questions

I am not sure if the title is accurate. I have several classes like
I have several controllers that take an instance of different classes each (Email, Call,
I am writing some PHP. I have several classes that do not declare any
Assume you have several arbitrary classes like below: class Foo { $foovar; public function
I have several classes with static const data members. I would like to know
i have several classes with members called 'Id'. Originally i wanted to store these
I have several classes, that all derives from SuperClass. When the classes are created,
I have several classes such as Order, Customer, etc. These classes serve for holding
I have several classes each containing several methods annotated with @Test . The classes
I have several classes, and want to work with their collections like with a

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.