What is this macro for at the beginning of a class definition?

前端 未结 3 848
無奈伤痛
無奈伤痛 2021-01-14 05:35

I\'m looking through the source of a library and many classes are defined using the following form

class THING_API ClassName 
{
...

Jumping

3条回答
  •  忘掉有多难
    2021-01-14 06:13

    One possible use would be to allow you to conditionally mark the class as callable from other libraries in a cross-platform library.

    class ClassName
    

    would be callable on Windows using MSVC but you'd need

    class __attribute__ ((visibility("default"))) ClassName
    

    for linux using gcc.

    In this case, THING_API might be defined like

    #ifdef _WIN32
    # define THING_API
    #else
    # define THING_API __attribute__ ((visibility("default")))
    #endif
    

提交回复
热议问题