0

I have used a LOG_MACRO(..) in my project which I want to upgrade it to not do anything if its used in some defined classes. I did it by template specialization. but I get compile error in static functions. since 'this' is not available there.

I need a magical macro to give me the class of current member function. if I use it in static function it must gives void.

template<class T> struct ZZLogDisable { static constexpr bool Value = false; };

//this will give me compile error if used in static functions since this is not available there
#define LOG_MACRO(msg) if(!ZZLogDisable<std::remove_reference<decltype(*this)>::type>::Value) {  printf(msg); }
//disable logging for a class
#define DISABLE_LOG(Class) template<> struct ZZLogDisable<Class> { static constexpr bool Value = true; };
UPO33
  • 19
  • 1
  • `printf(msg)` should be `printf("%s", msg)`. – melpomene Dec 11 '18 at 07:55
  • There are similar (same) questions about this, unfortunately no solutions. https://stackoverflow.com/questions/21143275/c-type-of-enclosing-class-in-static-member-function, https://stackoverflow.com/questions/21143835/can-i-implement-an-autonomous-self-member-type-in-c – geza Dec 11 '18 at 08:08

0 Answers0