how to pass a vector to a function

This is a discussion on how to pass a vector to a function within the C++ Programming forums, part of the General Programming Boards category; how to pass a vector to a function...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    78

    Smile how to pass a vector to a function

    how to pass a vector to a function

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    int somefunction(const vector<int> &vec);
    perhaps?

    Exactly how you do it depends on what you actually want to happen - the const in the above says "somefunction promises not to to change vector".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Instead of posting every question you have, you should actually go read some tutorials.

    After all, there is a reason why professors get paid to give lectures.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    78
    hi MacGyver , if u have problem answering my questions simply ignore it, but dont make unneceesary comments!

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    78
    thanks matsp, i will try it

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by chintugavali View Post
    hi MacGyver , if u have problem answering my questions simply ignore it, but dont make unneceesary comments!
    I think MacGyvers comment was more for your benefit - you will at some point or another need to find a process or acquiring information in other ways than asking each individual detail on a forum.

    Most people attend a forum just BECAUSE they like answering questions. But a question like yours is both simple and difficult, because it so much depends on "how you mean", and writing out ALL of the necessary information would be difficult - and it has already been done in books and tutorials.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    I'm making a very necessary comment. If you don't like it, just because you're particularly lazy and don't feel like reading a tutorial, I really don't care.

    Being a programmer is more than just typing text and making the computer do something. Brain dead users can type in text and make the computer do something. Real programmers need to be able to come up with solutions on the fly to various problems that they may have never seen before. In order to achieve this, you have to learn how to properly learn. Asking someone to teach you something is usually not something you can do. If you're a professional programmer, then you can't ask us every little detail for something you're working on. Another thing to consider is that there is information all over the Internet on how to learn how to program. This isn't the Dark Ages. You can find the information you need. The test of a diligent worker is to see how they find and utilize this knowledge.

    If you learn how to learn, you are closer on your way to being a good programmer. Part of this is learning how to glean information from tutorials and books. There is nothing wrong with asking people when you get stuck. No sense in reinventing the wheel everytime, however, if you're not going to think for yourself, there's no reason for us to help you. After all, why should anyone help you if you won't help yourself?

    Show us you've made an effort.

    Edit: matsp is exactly right. You need to be able to research information yourself because it's only going to get harder until you finally master the language. Little details of syntax is what you need to personally work on. If you've been spoon-fed everything, how are you going to be able to learn the more advanced concepts? I don't know how many people you will find on forums to teach you everything in a lecture-style approach.
    Last edited by MacGyver; 12-20-2007 at 07:38 PM.

  8. #8
    Registered User
    Join Date
    Dec 2007
    Posts
    78

    Lightbulb sorry

    sorry MacGyver, i will try to learn myself before asking any question on this forum...

  9. #9
    Registered User
    Join Date
    Dec 2007
    Location
    North Georgia Mountains
    Posts
    11
    there are a number of wonderful books listed at near the start of this list - try reading a few and following the examples. Try googling for Thinking in C Plus Plus - wonderful book and free online

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM

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