How to avoid "(void)a" cast causing side-effects?

Viewed 379

I have this code and GCC prints "what!?". How can I avoid that, so that the void cast simply has the C meaning "Ignore the lonely 'a;'"?

#include <iostream>

struct A {
  template<typename T>
  operator T() { 
    std::cout << "what!?";
  }
};

int main() {
  A a;
  (void)a;
}
2 Answers
Related