0

I am learning C++. Say we have a class declaration in the form of:

class SomeClass {
  public: 
    const Type* MyMethod(int64_t id) const;
}

What does the second const mean? There is nothing to the right of the const, so I am confused what it is modifying.

I tried using the Clockwise/Spiral Rule to detangle this, which suggests: "MyMethod() is const and returns a const Type pointer". Is that a correct read?

zthomas.nc
  • 3,689
  • 8
  • 35
  • 49
  • 1
    `MyMethod` is only allowed to call const member functions of `SomeClass` and may not modify its member variables. – drescherjm Apr 13 '22 at 16:33
  • The `const` qualifies the thing to its immediate **left** (with the exception-to-the-rule being when `const` appears first, then it qualifies the thing to its immediate right). And after the member function the thing to its immediate left is the invisible `this`, making it as-if you had `SomeClass const* const this` rather than `SomeClass* const this`. – Eljay Apr 13 '22 at 16:43

0 Answers0