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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:48:42+00:00 2026-05-14T08:48:42+00:00

I have a GUI architecture wherein elements fire events like so: guiManager->fireEvent(BUTTON_CLICKED, this); Every

  • 0

I have a GUI architecture wherein elements fire events like so:

guiManager->fireEvent(BUTTON_CLICKED, this);

Every single event fired passes ‘this’ as the caller of the event. There is never a time I dont want to pass ‘this’, and further, no pointer except for ‘this’ should ever be passed.

This brings me to a problem: How can I assert that fireEvent is never given a pointer other than ‘this’, and how can I simplify (and homogenize) calls to fireEvent to just:

guiManager->fireEvent(BUTTON_CLICKED);

At this point, I’m reminded of a fairly common compiler error when you write something like this:

class A {
public:
    void foo() {}
};

class B {
    void oops() { const A* a = new A; a->foo(); }
};

int main() {
    return 0;
}

Compiling this will give you

In member function
‘void B::oops()’:
error: passing
‘const A’ as ‘this’ argument of ‘void
A::foo()’ discards qualifiers

because member functions pass ‘this’ as a hidden parameter.

“Aha!” I say. This (no pun intended) is exactly what I want. If I could somehow access the hidden ‘this’ pointer, it would solve both issues I mentioned earlier. The problem is, as far as I know you can’t (can you?) and if you could, there would be outcries of “but it would break encapsulation!” Except I’m already passing ‘this’ every time, so what more could it break.

So, is there a way to access the hidden ‘this’, and if not are there any idioms or alternative approaches that are more elegant than passing ‘this’ every time?

  • 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-14T08:48:43+00:00Added an answer on May 14, 2026 at 8:48 am

    You could define

    void Element::fireEvent(EVENT e) {
       guiManager->fireEvent(e, this);
    }
    

    to save yourself a bit of writing each time. You’re going to have to call it with this at some point, since the guiManager needs to know which Element called fireEvent.

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

Sidebar

Related Questions

i have this GUI screen shots from the design team which i needs to
I have a GUI program, which would call a cmd in this GUI program.
I have a GUI program with one Exit button. When clicking this button, it
Broad design/architecture question. If you have nested components in a GUI, what's the most
I am working with the MVC architecture. I have my GUI all set up,
For architecture and design purposes I would like to design my GUI with a
I have a GUI that is going to do a lot of disparate tasks.
I have a GUI app written in C++/CLI which has a load of configurable
I have a GUI C++ application (Visual Studio 2008) that needs to be converted
I have a GUI tool that manages state sequences. One component is a 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.