Thread: How to add data and function as the program is running

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    7

    How to add data and function as the program is running

    can you give me an example? thanks!

  2. #2
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    Could you be more specific? What exactly are you asking?

    Brendan
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    7
    How to add data and function as the program is running

  4. #4
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    Do you mean like...be able to accept user input, but in the meantime do something else? If so, you use the kbhit() function...it's in, er..."conio.h" if you have it. It would work like so.
    Code:
    for(;;)
    {
         if(kbhit())
              break;
    
         cout << '.';
    }
    I hope that helps. If that wasn't what you were asking...then, er...hope it helps anyways

    Brendan
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    7
    thank you for your reply,but you didn't understand my problem.
    the data is a member data of the class ,and the function is a member function of the class. i want to add them to an object when the program is running .

    sorry,my english is poor

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    7
    who can help me!!

  7. #7
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Maybe you should look into shared libraries, that is, DLL for Windows and .so for Linux (probably for Unix as well).
    That's the best I can think with what you've said.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

  8. #8
    'AlHamdulillah
    Join Date
    Feb 2003
    Posts
    790
    could you try focusing and making a coherent paragraph on the exact details of what you want?

  9. #9
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    Uhm... whats so complicated about his question? He want's to add functions and data (variables) to a class or an instance of that class at runtime. imho.

    That said, unfortunatly I have no clue how to do it or if it is even possible in C++. I have a more or less similar problem right now, but I guess I better open another thread for it.
    Last edited by darksaidin; 08-23-2003 at 02:34 PM.

  10. #10
    Registered User
    Join Date
    Feb 2002
    Posts
    114
    maybe you want to use virtual function tables (code your own) and dito for variables...


    something like:

    Code:
    map<string, function_type> function_list;
    
    addFunction(function_pointer, function_name){
    function_list[function_name] = function_pointer
    }
    
    callFunction(function_name){
    (function_type&)function_list[function_name]()
    }
    its late in night so excuse the pseudo code and no real example...

    same goes for variables, but in the case of variables you ave to have a type that can be any value, so i propose some kind of templated type... i think the boost lib have an all purpose data type... oh.. by the way, same thing goes for functions and parameters/return value.

    its quite a complicated system you are planing on implementing, so maybe you should look up some scripting lib like lua and a loot others?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM