mercredi 30 janvier 2019

Call methods through macro expansion

I have this code:

class A {
public:
  bool has_foo() { return true; }
};

int main() {
  A a;

  CALL(a, foo);
}

I'd like to call the method has_foo through macro expansion:

#define CALL(object, method) do { object.has_ ## method ## (); } while(0)

The code above compiles on MSVC, but fails with GCC.

I would like to use macro expansion in order to avoid runtime overhead.

Aucun commentaire:

Enregistrer un commentaire