func returning array

This is a discussion on func returning array within the C++ Programming forums, part of the General Programming Boards category; Code: char foooo()[10] { static char a[10]; return a; } I am really screwed up! What's wrong here?...

  1. #1
    msp
    msp is offline
    Registered User msp's Avatar
    Join Date
    Jul 2007
    Location
    in
    Posts
    31

    Angry func returning array

    Code:
    char foooo()[10]
    {
    	static char a[10];
    	return a;
    }
    I am really screwed up! What's wrong here?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,448
    More like:
    Code:
    char* foooo()
    {
    	static char a[10];
    	return a;
    }
    Though have you considered encapsulating this in a class instead?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    msp
    msp is offline
    Registered User msp's Avatar
    Join Date
    Jul 2007
    Location
    in
    Posts
    31
    so this was a syntax error? really?
    when i write it like this:
    Code:
    char foooo()[10]
    {
    }
    my compiler reports that the function returns array! i am using MSVS .Net 2003.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,448
    I think the problem is that functions cannot return arrays. They can, however, return pointers to arrays.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  2. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  3. Replies: 6
    Last Post: 10-21-2003, 09:57 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 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