Thread: Looking to give script-like interface to program. (or something)

  1. #16
    The larch
    Join Date
    May 2006
    current is a pointer to an object and therefore you'll need to dereference it properly to call the operator().

                      << (*current)(val)
    Apparently brackets make a difference here: 1) dereference current (and current only), 2) call operator() on the dereferenced object.

    In addition the base-class needs to declare a virtual float operator()(int), otherwise you'll be trying to call a method through a base pointer that the base class doesn't have.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  2. #17
    Join Date
    Oct 2007
    Inside my computer
    Actually hey, it's possible to use a class to emulate a function pointer:
    typedef float (CallbackPtr)(float);
    class CCallback
    	CCallback(CallbackPtr CallbackFnc) : m_Callback(CallbackFnc) { }
    	operator CallbackPtr* () { return m_Callback; }
    	CallbackPtr* m_Callback;
    float Help2(float n) { return n; }
    void Help()
    	CCallback c = &Help2;
    	float f = c(1.0f);
    Pretty cool. I'll leave you to experiment on that if you wish to use it.
    The original error was also that the constructor only takes std::string and not an int
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Ethernal Noob
    Join Date
    Nov 2001
    What I'm really doing is modeling a function as you would write it on paper. In order to do that I need the "whole" function for each operation. For this it has to be in a vector of functions
    so something like

    cos(x) + x^2 + ax * 2

    would go into a vector and look like
    funcallback Array
    well i solved calling it, I just made the notation
    and it works.

    Elysia C++ offers function callbacks, which is what I'm using, so you don't really need to do all that for function objects, just use the overloaded operator() in a class.
    Last edited by indigo0086; 01-26-2008 at 06:36 PM.

  4. #19
    Ethernal Noob
    Join Date
    Nov 2001
    ok so I think I solved the situation, here will be the basic idea of my programs
    class FunCallback
            std::string name;   ///<the name of the function
            double input;      ///<the input of the function
            FunCallback(std::string label);
            virtual double operator()(double in);
            operator std::string();
            virtual ~FunCallback();
    //would basically represent a single constant that returns it's input value upon
    class IdCb: public FunCallback
            IdCb(double in);   
            double operator()(double in);
    I have others like these. Some that take constructors, some that don't. THis would allow me to create a factory class that reads an input file and generate a function definition via an array of these things.

    They'll have to all be doubles because you can't have overloaded type returns.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Script in games
    By Shakti in forum Game Programming
    Replies: 7
    Last Post: 09-27-2006, 12:27 AM
  4. Execute Program Using VB Script
    By brett2 in forum Windows Programming
    Replies: 0
    Last Post: 08-30-2003, 12:40 PM
  5. Replies: 1
    Last Post: 10-01-2001, 10:39 AM