-1

We can find:

1)

const char *get() { return str; }

2)

int get() const { return A; }

What is the differences of "const" in this two different parts of the function?

Pablo De Luca
  • 795
  • 3
  • 15
  • 29

1 Answers1

0

The first returns a pointer to a char which is constant - the value of str cannot be modified. This is used to create an unchangable thing.

The second returns an int (from A) which doesn't modify the state of the class - hence can be called when the class is constant.

mksteve
  • 12,614
  • 3
  • 28
  • 50