Is there a standard C header file which assigns a numeric value to all of the primitive types?

前端 未结 2 1467
说谎
说谎 2020-12-21 10:51

I have some code which performs differently depending on the underlying data type. EG:

void *some_data = obtain_data();
int data_type = obtain_data_type();
         


        
2条回答
  •  隐瞒了意图╮
    2020-12-21 11:49

    This is called in C++ a variant type. There are many libraries that do this for you, such as:

    1. QVariant from Qt
    2. Boost any

    But remember that there's a price to pay when using such a library. Things are not most efficient when you use variants, but some times it's necessary, such as when you use OPC/UA protocols.

提交回复
热议问题