0

I dont understand the difference between these 2:

const subclass* class::memeber(size_t i, size_t j) const

subclass* class::member(size_t i, size_t j)

(access to subclass at (i, j) )

I don't understand why in class we declared these two if I remember correctly one gets the copy of the address of the subclass and the other gets the address itself and forbids to change it. But why would we want to get the address itself if we don't want to change it?

T.K
  • 41
  • 7
  • Not quite. See https://stackoverflow.com/questions/1143262/what-is-the-difference-between-const-int-const-int-const-and-int-const – Lukas-T Dec 27 '20 at 13:48
  • This has nothing to do whatsoever with copies or addresses. – Sam Varshavchik Dec 27 '20 at 13:48
  • The overload with `const` at the end is chosen when `member` is called on a `const`-qualified instance of `class`. It then returns a pointer to `const`-qualified instance of `subclass`, in effect propagating the constness. The other overload is chosen when `member` is called on a non-`const` instance of `class`, and returns a pointer to non-`const` instances of `subclass`. In other words, `const` at the end determines whether `this` pointer inside `member` is of type `const class*` or `class*` – Igor Tandetnik Dec 27 '20 at 13:51
  • 1
    There's no difference between an address and a copy of an address, they're both still the same address. It's like saying there's a difference between an integer and a copy of that integer. – john Dec 27 '20 at 13:59

0 Answers0