jeudi 25 juin 2015

Is it possible to auto add some code, when I add class member variables

I'm boost newbie.

I would like to know is it possible

When I add some class member variable(at header file) then automatically generate some code

// classA.h file
class classA
{
    public:
        int a;
        int b;
        // I will add "int c;"

        void save(); // I want to auto generate some code at save()
        void load();
}

When I add "int c;"

// classA.cpp
void classA::save()
{
    someStream << a << b; // I use boost::serialize

    // I want auto replace above code by next
    // someStream << a << b << c;
}

void classA::load()
{
    someStream >> a >> b;

    // replace above 
    // someStream >> a >> b >> c;
    // Exactly same order
}
enter code here

It is possible? using boost mpl? macro?

I have variable to add a lot.

Aucun commentaire:

Enregistrer un commentaire