Why would you use 'extern “C++”'?

前端 未结 10 1434
失恋的感觉
失恋的感觉 2020-12-12 17:37

In this article the keyword extern can be followed by \"C\" or \"C++\". Why would you use \'extern \"C++\"\'? Is it practical?

10条回答
  •  一向
    一向 (楼主)
    2020-12-12 18:42

    The language permits:

    extern "C" {
      #include "foo.h"
    }
    

    What if foo.h contains something which requires C++ linkage?

        void f_plain(const char *);
        extern "C++" void f_fancy(const std::string &);
    

    That's how you keep the linker happy.

提交回复
热议问题