0

Am I to understand from

Stroutrup C++ Programming Language - Invariants

that the notation above is a range initializer or is this interpretive instruction to convey mathematically that the Vector class array range is between 0 and some predetermined size?

Should I even be using this book because it contains errors such as accessing a struct member from a variable of that struct using . instead of ->?

Mushy
  • 2,535
  • 10
  • 33
  • 54
  • 2
    The "error" is not an error, you're wrong.... – Rakete1111 Sep 29 '17 at 19:06
  • 2
    I think what you're looking at is a [half-closed interval](http://mathworld.wolfram.com/Half-ClosedInterval.html). – Fred Larson Sep 29 '17 at 19:06
  • @Rakete1111 Can you please demonstrate accessing a struct member through a pointer to struct? – Mushy Sep 29 '17 at 19:14
  • @FredLarson Is that legal syntax in C++ or is the author illustrating a point using half-closed interval? – Mushy Sep 29 '17 at 19:15
  • 1
    It's not legal C++ syntax, but you haven't given any context that indicates it was a code example. – Fred Larson Sep 29 '17 at 19:16
  • @FredLarson If you have the book I mentioned or access to it it's on page 56 first paragraph. I was simply wondering if the author was utilizing some neat syntax trick. – Mushy Sep 29 '17 at 19:18
  • @Mushy You are asking something else, but [demo for both](https://godbolt.org/g/hJnatS). – Rakete1111 Sep 29 '17 at 19:18
  • @Rakete1111 I got it; He's accessing the struct from argument – Mushy Sep 29 '17 at 19:25
  • BTW, note that this book is included in the [Definitive C++ Book Guide and List](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Bjarne Stroustrup created C++ and is one of the foremost authorities on the language. – Fred Larson Sep 29 '17 at 20:45

1 Answers1

3

It's a half-closed interval. He's saying the index to a vector must be in the range of 0 up to but not including the vector's size. So 0 would be a valid index (assuming the vector is not empty), but size() would not. This is not a code example.

Fred Larson
  • 60,987
  • 18
  • 112
  • 174