Q:

Can you modify the ‘this pointer’ type in c++?

0

Can you modify the ‘this pointer’ type in c++?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

“this” pointer’s type can be modified in the function declaration by the const and volatile keywords. To declare a function that has either of these attributes, add the keyword(s) after the function argument list.

See the following code,

class Point
{
    unsigned X() const;
};
int main()
{
}

The above code declares a member function, X, in which the ‘this’ pointer is treated as a const pointer to a const object. Combinations of cv-mod-list options can be used, but they always modify the object pointed to by the ‘this’ pointer, not the pointer itself.

Remark:The ‘this’ pointer is always a const pointer. It can’t be reassigned. The const or volatile qualifiers used in the member function declaration apply to the class instance the ‘this’ pointer points at, in the scope of that function.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Interview Questions For Experienced

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Can I use realloc() on pointers allocated via new ... >>
<< Can you change ‘this pointer’ of an object to ...