Vector Functions

This is a discussion on Vector Functions within the C++ Programming forums, part of the General Programming Boards category; I was wondering how to use a vector in a function in the following form. batt::additem( vector <int> inv, int ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    22

    Question Vector Functions

    I was wondering how to use a vector in a function in the following form.

    batt::additem( vector <int> inv, int id );

    Is that correct or will it raise errors?

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,525
    Well, you made a copy of a vector when you probably wanted a reference instead, but it should be fine.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    22
    thanks citizen!

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Learn about iterators, c89c. They are a much better way to pass vectors to functions. And this is especially true when you have a big vector.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21