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:
- Iterate the pairs
- Get return of memberFunction (together with the Project instance)
- 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