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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:12:06+00:00 2026-06-15T22:12:06+00:00

Related question: template-function-is-same-in-template-classes I’m a bit disconcerted with the type of the pointer this

  • 0

Related question: template-function-is-same-in-template-classes

I’m a bit disconcerted with the type of the pointer “this” (gcc 4.7.2, c++11). In principle, the type of pointer “this” of a non-const object of type C, for example, is “C * const”, and thus, the type of “*this” is “C”. But the behaviour of the “is_same” class confused me.

Test:

// this-type.cpp
#include <iostream>
#include <type_traits>

using namespace std;

class C
{
public:
   void test()
   {
       cout << boolalpha;

       cout << "'this' const?" << "              "
            << is_const<decltype(this)>::value << endl;

       cout << "'*this' const?" << "             "
            << is_const<decltype(*this)>::value << endl;

       cout << "'*this' and 'C' the same?" << "  "
            << is_same<decltype(*this), C>::value << endl;

       cout << "'this' and 'C*' the same?" << "  "
            << is_same<decltype(this), C*>::value << endl;
   }
};

int main()
{
    C c;

    c.test();
}

Output:

$ g++ --version | grep g++
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
$ g++ -std=c++11 this-type.cpp
$ ./a.out
'this' const?              false
'*this' const?             false
'*this' and 'C' the same?  false
'this' and 'C*' the same?  true

However, the expected output is:

$./a.out
'this' const?              true   // C* const
'*this' const?             false  // C
'*this' and 'C' the same?  true
'this' and 'C*' the same?  false  // C* const vs. C*

What are happened here?

  • 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-06-15T22:12:08+00:00Added an answer on June 15, 2026 at 10:12 pm

    In this case, the type of this is C *

    9.3.2 The this pointer [class.this]

    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*.

    …

    No mention for X *const, etc. The this pointer is a prvalue, that’s why it cannot be assigned to, not because it const-qualified.

    PS. By the way, it seems

    C *p; // for any type C
    is_same<declype (*p), C &>::value == true
    

    though it may be an artefact of the implementation (compiler or is_same), because the standard says:

    5.3.1 Unary operators [expr.unary.op]

    1 …

    … If the type of the expression is “pointer to T,” the type of the result is “T.” …

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

Sidebar

Related Questions

This may sound as a non related coding question but it's directly related :
This is partly related to this SO question . I have two classes, both
Kind of related to this question: https://stackoverflow.com/questions/8708525/how-to-check-if-mako-function-exist I want to check if a function
This question is an extension of this Related question . Taking Derick's advice, I
There is another possibly related question on this but it didn't have answers and
This is a related question to this but with EXISTS instead of IN SELECT
In a related question I asked how to get input via IUP . This
I found this related question: How do I use composition with inheritance? I would
This is a related question to one I posted earlier... I'm trying to sum
My question is related to numerical recipes. I have a global function which computes

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.