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

This is a discussion on Looking to give script-like interface to program. (or something) within the C++ Programming forums, part of the General Programming Boards category; current is a pointer to an object and therefore you'll need to dereference it properly to call the operator(). Code: ...

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

    Code:
                      << (*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
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    Actually hey, it's possible to use a class to emulate a function pointer:
    Code:
    typedef float (CallbackPtr)(float);
    class CCallback
    {
    public:
    	CCallback(CallbackPtr CallbackFnc) : m_Callback(CallbackFnc) { }
    	operator CallbackPtr* () { return m_Callback; }
    
    private:
    	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
    Posts
    1,901
    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
    Code:
    funcallback Array
    0|cosCallback|
    1|powCallback(2)|
    2|multCallback|
    3|identCallback(2)|
    well i solved calling it, I just made the notation
    Code:
    (*a)(4)
    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
    Posts
    1,901
    ok so I think I solved the situation, here will be the basic idea of my programs
    Code:
    class FunCallback
    {
        protected:
            std::string name;   ///<the name of the function
            double input;      ///<the input of the function
    
        public:
            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
    {
        public:
            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.

Page 2 of 2 FirstFirst 12
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, 01:27 AM
  4. Execute Program Using VB Script
    By brett2 in forum Windows Programming
    Replies: 0
    Last Post: 08-30-2003, 01:40 PM
  5. Replies: 1
    Last Post: 10-01-2001, 11:39 AM

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