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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:26:51+00:00 2026-05-28T04:26:51+00:00

Possible Duplicate: What are the differences between pointer variable and reference variable in C++?

  • 0

Possible Duplicate:
What are the differences between pointer variable and reference variable in C++?

This is confusing me:

class CDummy 
{
public:
   int isitme (CDummy& param);
};

int CDummy::isitme (CDummy& param)
{
  if (&param == this)
  { 
       return true; //ampersand sign on left side??
  }
  else 
  {    
       return false;
  }
}

int main () 
{
  CDummy a;
  CDummy* b = &a;

  if ( b->isitme(a) )
  {
    cout << "yes, &a is b";
  }

  return 0;
}

In C & usually means the address of a var. What does it mean here? Is this a fancy way of pointer notation?

The reason I am assuming it is a pointer notation because this is a pointer after all and we are checking for equality of two pointers.

I am studying from cplusplus.com and they have this example.

  • 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-28T04:26:51+00:00Added an answer on May 28, 2026 at 4:26 am

    To start, note that

    this
    

    is a special pointer ( == memory address) to the class its in.
    First, an object is instantiated:

    CDummy a;
    

    Next, a pointer is instantiated:

    CDummy *b;
    

    Next, the memory address of a is assigned to the pointer b:

    b = &a;
    

    Next, the method CDummy::isitme(CDummy &param) is called:

    b->isitme(a);
    

    A test is evaluated inside this method:

    if (&param == this) // do something
    

    Here’s the tricky part. param is an object of type CDummy, but &param is the memory address of param. So the memory address of param is tested against another memory address called “this“. If you copy the memory address of the object this method is called from into the argument of this method, this will result in true.

    This kind of evaluation is usually done when overloading the copy constructor

    MyClass& MyClass::operator=(const MyClass &other) {
        // if a programmer tries to copy the same object into itself, protect
        // from this behavior via this route
        if (&other == this) return *this;
        else {
            // otherwise truly copy other into this
        }
    }
    

    Also note the usage of *this, where this is being dereferenced. That is, instead of returning the memory address, return the object located at that memory address.

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

Sidebar

Related Questions

Possible Duplicate: What are the differences between pointer variable and reference variable in C++?
Possible Duplicate: Difference between pointer variable and reference variable in C++ I saw this
Possible Duplicate: What are the differences between pointer variable and reference variable in C++?
Possible Duplicate: What are the differences between pointer variable and reference variable in C++?
Possible Duplicate: Difference between pointer variable and reference variable in C++ When should I
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading
Possible Duplicate: What are the differences between struct and class in C++ http://www.cplusplus.com/reference/std/typeinfo/type_info/ I
Possible Duplicate: Difference between pointer variable and reference variable in C++ As I am
Possible Duplicate: Difference between pointer variable and reference variable in C++ suppose I'm trying
Possible Duplicate: What are the differences between using int[][] and int[,]? I just came

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.