Using Function objects to define valid operations on other objects

This is a discussion on Using Function objects to define valid operations on other objects within the C++ Programming forums, part of the General Programming Boards category; Consider that I've several objects of a token class...some of them being operands and most others being operators and functions. ...

  1. #1
    Registered User manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    Kolkata@India
    Posts
    2,505

    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..
    Manasij Mukherjee | gcc-4.8.2 @Arch Linux
    Slow and Steady wins the race... if and only if :
    1.None of the other participants are fast and steady.
    2.The fast and unsteady suddenly falls asleep while running !



  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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, 07:37 PM
  2. Matrix operations using objects
    By circuitbreaker in forum C++ Programming
    Replies: 7
    Last Post: 05-04-2010, 09:53 AM
  3. vector of function objects
    By idleman in forum C++ Programming
    Replies: 6
    Last Post: 09-11-2009, 12:59 PM
  4. Replies: 4
    Last Post: 10-16-2003, 12:26 PM
  5. Objects, or pointers to objects?
    By Unregistered in forum C++ Programming
    Replies: 5
    Last Post: 12-18-2001, 12:57 AM

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