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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:26:54+00:00 2026-05-26T14:26:54+00:00

I made a simple class to represent a door. To return the variables, I’m

  • 0

I made a simple class to represent a door. To return the variables, I’m accessing them with the this pointer. With respect to just accessing variables, what’s the difference between accessing them with the this pointer and without?

class Door
{
protected:
    bool shut; // true if shut, false if not shut
public:
    Door(); // Constructs a shut door.
    bool isOpen(); // Is the door open?
    void Open(); // Opens the door, if possible. By default it
    // is always possible to open a generic door.
    void Close(); // Shuts the door.
};
Door::Door()
{}
bool Door::isOpen()
{
    return this->shut;
}
void Door::Open()
{
    this->shut = false;
}
void Door::Close()
{
    if(this->isOpen()) this->shut = true;
}

There may or may not be a difference here, but what about for more complex classes?

  • 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-26T14:26:54+00:00Added an answer on May 26, 2026 at 2:26 pm

    Nothing. The this pointer is automatically added if you exclude it.

    You only have to use it if you’re doing something like this:

    void Door::foo(bool shut)
    {
        this->shut = shut; // this is used to avoid ambiguity
    }
    

    More usages


    A brief overview:

    Think of methods as functions that pass a pointer as their first argument.

    void Door::foo(int x) { this->y = x; } // this keyword not needed
    

    is roughly equivilent to

    void foo(Door* this_ptr, int x) { this_ptr->y = x; }
    

    Methods just automate this.

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

Sidebar

Related Questions

I'm using this simple code: http://ejohn.org/blog/simple-javascript-inheritance/ Using this library, I made this simple class:
I made a simple javascript class like this: function Horse() { this.color = 'brown';
I'm just starting Java ... again. I just made a simple program class first
I was trying to learn CoffeeScript, and made this simple class as first try:
I made for myself this simple class for drawing text by lines into specific
I'm a beginner with JAX RS architecture. I've made a simple class like this:
So I have made this simple interface: package{ public interface GraphADT{ function addNode(newNode:Node):Boolean; }
I made a dead simple Console class in AS3 that allows logging to be
Trying to import a class I made in Dr. Java. I made a simple
I made a simple table class with pager for my project in php. It

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.