2 Replies - 219 Views - Last Post: 09 November 2017 - 06:19 AM Rate Topic: -----

#1 al-khwarizmi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-August 16

How does addition to an STL vector become an offset?

Posted 09 November 2017 - 05:40 AM

http://www.cplusplus...lgorithm/equal/

In the example given here, on line 12, it says:

std::vector<int>myvector (myints,myints+5);


How does that work exactly? I don't see the + operator as a member function of vectors on the same reference site.
Is This A Good Question/Topic? 0
  • +

Replies To: How does addition to an STL vector become an offset?

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2511
  • View blog
  • Posts: 3,983
  • Joined: 21-June 11

Re: How does addition to an STL vector become an offset?

Posted 09 November 2017 - 05:53 AM

myints is an array, not a vector. myints are implicitly convertible to pointers and pointers do have a + operator. Specifically p + i, where p is a pointer and i is an integer, produces a pointer that points to the location i elements after where p points to.
Was This Post Helpful? 2
  • +
  • -

#3 al-khwarizmi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-August 16

Re: How does addition to an STL vector become an offset?

Posted 09 November 2017 - 06:19 AM

I knew that. Just misread the example. Dammit. Thanks.

This post has been edited by Skydiver: 09 November 2017 - 06:38 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1