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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:04:25+00:00 2026-05-31T21:04:25+00:00

Imagine I have a class Window with a member function show which causes the

  • 0

Imagine I have a class “Window” with a member function “show” which causes the underlying window to become visible on the screen.

Because I’m calling an underlying windows API to achieve this I’m not in any way altering the state of my “Window” object and yet clearly there is a large, obvious change in state of my window caused by calling this ( a window appearing on the screen and being able to be interacted with by users)

So I should declare my function as –

void Window::show() const;

because as far as the Window object is concerned this function doesn’t change any state and therefore can be called on “const Window” objects. But somehow that doesn’t seem right as calling that function clearly in some sense changes the state of the object.

  • 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-31T21:04:26+00:00Added an answer on May 31, 2026 at 9:04 pm

    What you’re probably grappling with is that C++ has no notion of purity, that is, whether or not a function has side-effects. const member functions only make the promise that the state of the object itself will not be modified.

    However, some objects logically consist of more state than what the instance actually contains. This comes up very often when an object’s role is to interact with state managed by another library—especially a GUI library.

    Therefore, while show() can incidentally be marked const, it logically should not be. If it were truly const, then you would expect a function such as is_visible() to return the same value both before and after the call to show(), and clearly that is not the case.

    In other words, const functions are those that change nothing about the object that you can observe through its public interface. That’s the reasoning behind, for example, marking some member functions const but using a mutable member to do internal bookkeeping.

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

Sidebar

Related Questions

Let me give you the following example: Imagine you have a window class which
Imagine I have a C++ class Foo and a class Bar which has to
Hi Imagine I have a class of StandardCar which holds a reference to an
Imagine I have an entity: public class MyObject { public string Name { get;
Imagine that I have a nice Deck class, in the best OO fashion. It
Imagine I have a table which stores a series of sparse vectors. A sparse
Imagine I have this code: var myFunc1 = function(event) { alert(1); } var myFunc2
I have a main class which creates and populates a DataSet and an instance
Imagine I have a class used to represent some trivial numerical data, like a
Imagine we have a class like this: class Testee { public: void Func() private:

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.