Is there a way to add parameters to macro list?

Viewed 68

Here is the thing :

I have made this macro :

#define CREATE_FROM_LIST(ClassName, List) \
class ClassName##Vars \
{\
public :\
    List(CREATE_GET_SET) \
};

#define CREATE_GET_SET(Name, Type) \
Type get##Name##() {/***/} \
void set##Name##() {/***/}

My goal is to create a class that will handle all the get/set of a set of variables.

I have this piece of code in a file :

#define MY_VAR_LIST(var) \
var(foo1, float) \
var(foo2, int) \
var(foo3, char)

CREATE_FROM_LIST(FooManager, MY_VAR_LIST)

And I get the expected result when I expand the macro :

class FooManagerVars
{
public:
    float getfoo1() {/***/}
    void setfoo1() {/***/}
    /* same thing for foo2 and foo3*/
};

But now I would like to separate the definition and the declaration of the get/set methods. I would like to call one macro to create the class with the declarations, and another one to create the definitions.

My problem is that, in order to create the definitions, I need the ClassName :

Type ClassName##Vars::get##Name() {/***/}

But I cannot figure out how I can have the list parameters (Type, Name) and the ClassName at the same time without passing the ClassName as a parameter in all the vars of the list.

0 Answers
Related