vendredi 20 avril 2018

C++ macro '##' doesn't work after '->' operator

I have a shared_ptr object x, which has get and set methods as follows:

x->a_value();
x->set_a_value();
x->b_value();
x->set_b_value();

When i try to define a macro:

#define MAC(type) \
x->set_##type##_value(val);

MAC(a)

It works fine, but when I do:

#define MAC(type) \
  x->##type##_value();

MAC(a)

it gives the following compile error: pasting formed '->a', an invalid preprocessing token

Aucun commentaire:

Enregistrer un commentaire