How to know if the argument that is passed to the function is a class, union or enum in c++?

前端 未结 4 442
伪装坚强ぢ
伪装坚强ぢ 2021-01-03 07:14

I want to define an operator<< for all enums, to cout the value and print that it is an enum like this:

code:

enum AnyEnum{A,B,C};
AnyEnum enm          


        
4条回答
  •  耶瑟儿~
    2021-01-03 08:04

    This is usually done with compiler hooks. The compiler has special functions that "fill" the template with the apropriate value (at least in C++0x where type_traits has been standardized). For instance the is_pod trait uses the __is_pod compiler hook under VC 10 to get the apropriate information.

提交回复
热议问题