Thread: Using Function objects to define valid operations on other objects

  1. #1
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657

    Using Function objects to define valid operations on other objects

    Consider that I've several objects of a token class...some of them being operands and most others being operators and functions.
    How do I implement the ( ) overload , such that, when I call
    Code:
    random_object(<pointer to operand stack>) ;
    ..the particular operation takes place?..I thought about placing function pointers but can not do so in a good way..(i.e..which does not involve dozens of switch cases..!)..
    Any hint is welcome..

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    If Token[0] was a number token, and Token[1] was a function token, and Token[2] was another number token, then you would want
    Code:
    Token[1].fn_object(Token[0], Token[2]);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Utility of Function Objects
    By manasij7479 in forum Tech Board
    Replies: 16
    Last Post: 05-25-2011, 06:37 PM
  2. Matrix operations using objects
    By circuitbreaker in forum C++ Programming
    Replies: 7
    Last Post: 05-04-2010, 08:53 AM
  3. vector of function objects
    By idleman in forum C++ Programming
    Replies: 6
    Last Post: 09-11-2009, 11:59 AM
  4. Replies: 4
    Last Post: 10-16-2003, 11:26 AM
  5. Objects, or pointers to objects?
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 12-18-2001, 12:57 AM