Thread: Calling Function via function pointer inside a structure pointer

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    16

    Calling Function via function pointer inside a structure pointer

    I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.
    Code:
    position = hash->(*funcHash)(idNmbr);
    The function will return an int, which is what position is a type of. When I compile this code, I get the error: error: expected identifier before ‘(’ token.
    Is my syntax wrong? I'm not sure what would be throwing this error.

  2. #2
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Too many words, too little code. I am fan of code, not words (even though you may give all the information needed via words). Post some code. Do not worry, nobody is going to steal your code :P
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    16
    Code:
    struct onode* addOrder(struct hashStorage* hash, struct order* data) {  
      struct onode *newOrder;
      int position, idNmbr;
      idNmbr = data->id;
      newOrder = newNode(data);
      position = hash->(*funcHash)(idNmbr);
    }

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Just use
    Code:
    position = hash->funcHash(idNmbr);
    Bye, Andreas

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Referencing pointer inside a structure pointer
    By SasDutta in forum C Programming
    Replies: 2
    Last Post: 11-11-2010, 11:33 AM
  2. Pointer to a class inside the WindowsProcedure function
    By like_no_other in forum Windows Programming
    Replies: 3
    Last Post: 06-01-2009, 12:52 PM
  3. Changing pointer inside function?
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 07-20-2008, 05:10 AM
  4. pointer assignment inside a function ???
    By gemini_shooter in forum C Programming
    Replies: 7
    Last Post: 05-04-2005, 11:30 AM
  5. how to use a member function inside a function pointer?
    By mickey in forum C++ Programming
    Replies: 6
    Last Post: 10-17-2002, 04:27 AM