Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8590653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:20:39+00:00 2026-06-11T23:20:39+00:00

Problem Assume there is a set of different functions. Each of there functions may

  • 0

Problem

Assume there is a set of different functions. Each of there functions may be a member function of some object, and may take an arbitary number of arguments. For simplicity sake lets assume that each function has no more than 8 arguments of int, double or std::string types. For example:

class MyClass{
public:
  void DoA(int i);
  void DoB(double d, int i);
};

class YourClass{
public:
  void DoC(std::string s);
  void DoD(int i1, int i2, int i3);
};

Lets assume there is a file containing a series of records about functions. Each record contains name of the function to be called, its arguments values and pointer to the object for the member function. I need a way to read all this data from the file and execute functions in correct order with correct arguments.

It is okay to have names of the functions hard-coded, for example, but adding a new function to a libary should be as easy as possible.

Motivation

This is a part of roguelike game project I’m trying to create, specifically a save/load game system. Once a player tries to save his game, all events that have not yet occurred must be saved too, and next time the player loads the game events should be loaded and scheduled properly. Since roguelike is clearly needs a lot of space to expand, I don’t want to make any assumptions about the functions type.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:20:40+00:00Added an answer on June 11, 2026 at 11:20 pm

    Here’s an idea:

    class Foo
    {
        void f1_impl(double, char, int);
        void f2_impl(int, int);
    
        void func1(std::string s)
        {
            double d;
            char   c;
            int    i;
    
            std::tie(d, c, i) = parse<double, char, int>(std::move(s));
    
            f1_impl(d, c, i);
       }
    
       void func2(std::string s)
       {
            // similarly
       }
    };
    
    std::unordered_map<std::string, void (Foo::*)(std::string)> const functions
    {  { "function1", &Foo::func1 },
       { "function2", &Foo::func2 },
    };
    

    Input file:

    function1 1.250000,'a',2815
    function2 12,-80
    function2 99,111
    

    Parsing:

    Foo x;
    
    for (std::string line; std::getline(inputfile, line); )
    {
        std::string f, a;
    
        if (!(std::istringstream(line) >> f >> a)) { /* error */ }
    
        (x.*functions[f])(a);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume that there's no problem with my header file and some included library. I'm
This is inspired by/taken from this thread: http://www.allegro.cc/forums/thread/603383 The Problem Assume the user gives
Problem: I've a huge raw text file (assume of 3gig), I need to go
The problem is basically this, in python's gobject and gtk bindings. Assume we have
Ok. Here is a problem. This is my collection : {2,3,4,2,3,5} . Let's assume
Having problems iterating. Problem has to do with const correctness, I think. I assume
I am having some problems designing a schema for dynamic properties with versioning. Assume
Assume, for whatever reason, that we have three inline scripts on a page. Each
I need to count the quantiles for a large set of data. Let's assume
I have a set of measurements done regularly, but some are missing: measurement_date value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.