mercredi 8 mars 2017

C++ get return from references to member functions

I would like to store some settings made by the user. I have a class called Project and would like to store the values of the member. I've worked a lot with Java and now that it would be easy with reflection, but now I have to find a solution for c++.
My idea:

class Project
{
  Project();

  public:
  //Getter and Setter for private member...

  private:
    string   mProjectName;    //(="Test")
    string   mProjectCreator;
}

class ProjectParser
{
  ProjectParser();
  public:
    SaveProject(Project* aProjectPtr)
    {
      //do stuff with the example below
    }
}

The ProjectParser would contain a pair list like this:
std::pair<[memberName],[memberFunction]>("projectName",&Project::GetProjectName)...

SaveProject(Project* aProjectPtr) would do:

  1. Iterate the pairs
  2. Get return of memberFunction (together with the Project instance)
  3. Write value for memberName (for example in a JSON file or XML) projectName:"Test"

But beeing new to C++, I have no clue how to execute the member function for a instance of an object and how to get the return value. Is there a possibility to do it like this?





Aucun commentaire:

Enregistrer un commentaire