array of pfuncs in one statement

This is a discussion on array of pfuncs in one statement within the C++ Programming forums, part of the General Programming Boards category; I was fidgeting around with the compiler today and I tried to create an array of function pointers in one ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    75

    Question array of pfuncs in one statement

    I was fidgeting around with the compiler today and I tried to create an array of function pointers in one statement, but couldn't quite do it that directly. Or at least I can't figure it out.

    Here's what I tried:
    Code:
    void (*arrpfunc)[10](); // error: array element type cannot be a function
    typedef void (*pfunc)();
    pfunc arr[10]; // no problems.
    BTW, i'm using vstudio.net

  2. #2
    Speedy5
    Guest
    Simple:

    void (*arrpfunc[10])();

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    allrighty, that worked, thx.

  4. #4
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    Read it from the inside out starting at the identifier.
    Code:
    void (*arrpfunc)[10]();
    
           arrpfunc                 // is a
          *                         // pointer to
                    [10]            // an array of ten
                        ()          // functions?
    void                            // returning nothing
    Kinda goofy and doesn't make sense, right? :-) Try this instead
    Code:
    void (*arrpfunc[10])();
    
           arrpfunc                 // is an
                   [10]             // array of ten
          *                         // pointers to
                        ()          // functions
    void                            // returning nothing
    See? It only looks complicated when everything is squished together like that. :-)
    *Cela*

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    75
    Oh yeah, that style of thinking jumped out at me after seeing the correct code, but thx for the help anyway. i'm trying to read c++ programming language by bjarne stroustrup and so it goes into a lot of syntactical details like that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-25-2008, 12:50 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 08:51 AM
  3. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 07:31 AM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 03:49 PM

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