Array as a declaration specifier

This is a discussion on Array as a declaration specifier within the C++ Programming forums, part of the General Programming Boards category; Dear All, I want to write a function that returns an array of integers but I have a problem with ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    50

    Array as a declaration specifier

    Dear All,
    I want to write a function that returns an array of integers but I have a problem with the function definition
    Code:
     array <int> f(int a, int b, int c)
    {
    .
    .
    }
    How can I define this function?
    Thanks

  2. #2
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    Code:
    int *f( int a, int b, int c );
    You can't return an array in C++, so you have to return a pointer to the first element. A vector<> is better if youhave a choice:
    Code:
    vector<int> f( int a, int b, int c );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 1-D array
    By jack999 in forum C++ Programming
    Replies: 24
    Last Post: 05-12-2006, 07:01 PM
  2. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  3. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  4. array of pointer objects
    By Death_Wraith in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 07:06 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM

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