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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:06:37+00:00 2026-05-17T00:06:37+00:00

I’ve been reading about the this pointer on various sites (e.g. the MSDN manuals)

  • 0

I’ve been reading about the “this” pointer on various sites (e.g. the MSDN manuals) and understand its basic uses — returning a copy your own object or using a pointer of it for returns/comparison.

But I came across this statement:

  // Return an object that defines its own operator[] that will access the data.
  // The temp object is very trivial and just allows access to the data via 
  // operator[]
  VectorDeque2D_Inner_Set<T> operator[](unsigned int first_index) { 
    return VectorDeque2D_Inner_Set<T>(*this, first_index);
  }

What does that do? Does it somehow increment the this operator, and if so, why??

(This comes from an example I was given on stack overflow, so there may be mistakes in the syntax. Let me know if a bigger chunk is necessary, I can paste more code in.)


EDIT 1
Here’s the entire listing, for more info. The function is near the bottom of the class. Note I renamed the variable from x to index and renamed the templated inner class. I forgot to put the typecast to the templated inner-class, which I have added in this update.

Any ideas now?

template <typename T>
class Container
{
private:
    // ...


public:

    // Proxy object used to provide the second brackets
    template <typename T>
    class OperatorBracketHelper
    {
        Container<T> & parent;
        size_t firstIndex;
    public:
        OperatorBracketHelper(Container<T> & Parent, size_t FirstIndex) : parent(Parent), firstIndex(FirstIndex) {}

        // This is the method called for the "second brackets"
        T & operator[](size_t SecondIndex)
        {
            // Call the parent GetElement method which will actually retrieve the element
            return parent.GetElement(firstIndex, SecondIndex);
        }

    }

    // This is the method called for the "first brackets"
    OperatorBracketHelper<T> operator[](size_t FirstIndex)
    {
        // Return a proxy object that "knows" to which container it has to ask the element
        // and which is the first index (specified in this call)
        return OperatorBracketHelper<T>(*this, FirstIndex);
    }

    T & GetElement(size_t FirstIndex, size_t SecondIndex)
    {
        // Here the actual element retrieval is done
        // ...
    }
}
  • 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-17T00:06:38+00:00Added an answer on May 17, 2026 at 12:06 am

    The this keyword basically is a pointer reference to the object that it’s currently in use. In C++, this is a pointer, so to dereference it, use *this.

    So, this code,

    return VectorDeque2D_Inner_Set<T>(*this, index);
    

    returns a new VectorDeque2D_Inner_Set by passing a dereferenced of itself (since the constructor wants the reference of the object and not the pointer address).

    This method,

     // This is the method called for the "first brackets"
        OperatorBracketHelper<T> operator[](size_t FirstIndex)
        {
            // Return a proxy object that "knows" to which container it has to ask the element
            // and which is the first index (specified in this call)
            return OperatorBracketHelper<T>(*this, FirstIndex);
        }
    

    just passed a dereferenced self to the constructor OperatorBracketHelper as it requires a Container& as parameter.

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

Sidebar

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.