首页 > 解决方案 > Can I use C++ classes and class objects inside POSIX thread also function calls

问题描述

I like to know can I use C++ programming concepts in threads from pthread.h is there any limitation, if yes then what would that be. any information about documentation of C++ in Posix threads I am looking for

标签: c++clinuxpthreads

解决方案


C++ 旨在与 C 互操作,因此您可以在 C++ 中自由使用标准 C 库中的所有函数。唯一的限制是必须使用 C++ 进行开发。C++ 可以使用稍加修改或根本不修改的 C 函数,但反之则不然:C 只能使用 C 函数。为了能够包含 C++ 代码,您必须首先将 C++ 代码包装到

extern "C"

包装函数,并将您的使用限制为仅内部的那些函数,并将您的程序链接为 C++ 程序(这是初始化程序可以拥有的所有全局实例所必需的,在调用之前适当地调用构造函数main()


推荐阅读