-1

Possible Duplicate:
What is the difference between const int*, const int * const, and int const *?
const int = int const?

What's the difference between the following three?

vector<int const *> f() { ... }

vector<const int *> g() { ... }

vector<int * const> h() { ... }
Community
  • 1
  • 1
Łukasz Lew
  • 48,526
  • 41
  • 139
  • 208
  • this might help you with constant pointers and pointers to constants http://www.codeguru.com/cpp/cpp/cpp_mfc/general/article.php/c6967 – L7ColWinters Jan 27 '12 at 16:10
  • 1
    Probably not an exact duplicate. The answer, btw, is that the first two are the same, and the third is an error, as `int * const` does not comply with the requirements that `std::vector` places on the contained type (in particular assignability) – David Rodríguez - dribeas Jan 27 '12 at 19:02

3 Answers3

3

Nothing (except the name of the function).

In both cases, const modifies the int, not the pointer.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
2

There's no difference; int const and const int mean the same thing.

Ordinarily, const refers to the type on its left: a int const * is a pointer to a constant integer, not a constant pointer to a (non-constant) integer. Putting const at the very beginning is a special case, where it refers to the type on its right.

Wyzard
  • 33,849
  • 3
  • 67
  • 87
0

One's named f, the other is named g. That's it.

const is applied to the element to the left. In the case where there is no element to the left, it is applied to the element to the right.

Benjamin Lindley
  • 101,917
  • 9
  • 204
  • 274