Pointers?!

This is a discussion on Pointers?! within the C++ Programming forums, part of the General Programming Boards category; I have a function inside an object that I want to pass in an array to. I then want to ...

  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,796
    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, 09:33 AM
  4. Staticly Bound Member Function Pointers
    By Polymorphic OOP in forum C++ Programming
    Replies: 29
    Last Post: 11-28-2002, 12:18 PM

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