Thread: Pass array by reference help

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    73

    Pass array by reference help

    I need to pass an array of 10 instances of a custom class to a function. The snippets of code are posted below. How would I do this right?

    The prototype:
    Code:
    int Search(Vertex vertex[], ofstream &outfile);
    The implementation in the main function.
    Code:
    Search(vertex[10], outfile);

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Step 1 learn the meaning of implementation
    Step 2 learn the correct term to call/invoke a function.
    step 3 Write the implementation of the function.

    Edit: Suggest reading this http://cboard.cprogramming.com/cplus...-homework.html

    Tim S.
    Last edited by stahta01; 04-10-2014 at 10:26 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If vertex is an array, then omit the index, e.g.

    Search(vertex, outfile)

    If you include an index, then you would only pass a single element which is not your intention.
    Note that this passes the array by address, not reference.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how can i pass 2d and 3d array by reference?
    By johnny8888 in forum C++ Programming
    Replies: 9
    Last Post: 10-23-2011, 10:04 AM
  2. how to pass array by reference
    By dezz101 in forum C Programming
    Replies: 13
    Last Post: 09-19-2010, 09:28 AM
  3. Pass an array to a function by reference?
    By Loic in forum C++ Programming
    Replies: 3
    Last Post: 06-04-2007, 11:44 PM
  4. How to pass an array of strings by reference?`
    By JamesMI in forum C++ Programming
    Replies: 17
    Last Post: 01-25-2003, 08:23 PM
  5. How can I pass a reference from a array os a class
    By Nautilus in forum C++ Programming
    Replies: 7
    Last Post: 01-20-2003, 06:23 AM