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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:20:28+00:00 2026-05-22T15:20:28+00:00

As mentioned in the title, I would like to know about the type of

  • 0

As mentioned in the title, I would like to know about the type of 'this' pointer.

I’m working on a project and I observed that the type of 'this' pointer is "ClassName * const this" on windows using VC++ 2008. Well I would want to know what is the need/requirement to make the this pointer a constant pointer. Thanks.

  • 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-22T15:20:29+00:00Added an answer on May 22, 2026 at 3:20 pm

    The type of this pointer is either ClassName * or const ClassName *, depending on whether it is inspected inside a non-const or const method of the class ClassName. Pointer this is not an lvalue.

    class ClassName {
      void foo() {
        // here `this` has `ClassName *` type
      }
    
      void bar() const {
        // here `this` has `const ClassName *` type
      }
    };
    

    The observation you mentioned above is misleading. Pointer this is not an lvalue, which means that it cannot possibly have ClassName * const type, i.e. it cannot possible have a const to the right of the *. Non-lvalues of pointer type cannot be const or non-const. There’s simply no such concept in C++ language. What you observed must be an internal quirk of the specific compiler. Formally, it is incorrect.

    Here are the relevant quotes from the language specification (emphasis mine)

    9.3.2 The this pointer

    In the body of a non-static (9.3) member function, the keyword this is
    a prvalue expression whose value is the address of the object for
    which the function is called. The type of this in a member function of
    a class X is X*. If the member function is declared const, the type of
    this is const X*, if the member function is declared volatile, the
    type of this is volatile X*, and if the member function is declared
    const volatile, the type of this is const volatile X*.
    [ Note: thus in
    a const member function, the object for which the function is called
    is accessed through a const access path. —end note ]


    It is worth nothing that back in the C++98/C++03 times several compilers used an internal implementational trick: they interpreted their this pointers as constant pointers, e.g. ClassName *const in a non-constant method of class ClassName. This apparently helped them to ensure non-modifiablity of this. GCC and MSVC are known to have used the technique. It was a harmless trick, since at language level this was not an lvalue and its constness was undetectable. That extra const would generally reveal itself only in diagnostic messages issued by the compiler.

    However, with the advent of rvalue references in C++11 it became possible to detect this extra const on the type of this. For example, the following code is valid in C++11

    struct S
    {
      void foo() { S *&&r = this; }
    };
    

    Yet it will typically fail to compile in implementations that still use the aforementioned trick. GCC has since abandoned the technique. MSVC++ still uses it (as of VS2017), which prevents the above perfectly valid code from compiling in MSVC++.

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

Sidebar

Related Questions

Would what mentioned in the title be possible? Python module style that is. See
Is it possible what I have mentioned in the title? I would like to
I would like to mention about my little project, and if I'm on track.
I don't know how to title this more accurately. So I have dynamically generated
I would like to know how do I add an error check to below
I would like to change the text that appears in the ThickBox in the
As the title indicates, I would like to do the following, but the compiler
Refering to a previously asked question , I would like to know how to
My LogIn action originally looked like this: return new RedirectResult(nameValueCollection[ReturnUrl]); But, I would like
First off I'm not sure that's the proper title for this question but hopefully

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.