Thread: Pointers?!

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    14

    Pointers?!

    I have a function inside an object that I want to pass in an array to. I then want to modify it and pass it back. I assume the only way to do this is to use pointers to an array.

    How do i reference every position in the array and how do I pass it in and back?

    Thanks

    Rich

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Arrays are passed to functions as pointers to the first element. This is the default behavior in C++, so you can simply do something like this:
    Code:
    void object::function ( T array[], int size );
    Because the array is really a pointer, you have no way of calculating its size without help. So it's usually a good idea to pass the size of an array along with the array itself. Now you can modify the array however you want and the changes will persist back to the caller.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using pointers to pointers
    By steve1_rm in forum C Programming
    Replies: 18
    Last Post: 05-29-2008, 05:59 AM
  2. function pointers
    By benhaldor in forum C Programming
    Replies: 4
    Last Post: 08-19-2007, 10:56 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 01:18 PM