Integrate a C++ Library Class into a C Program

preview_player
Показать описание
Learn how to integrate a C++ Class into a C Program. First we start by defining a C++ class called EmbClass that has 1 private integer data member and 1 public set and get method. Next we create an EmbClass Wrapper called CWrapper that wraps around our C++ class using extern "C", so a C program can access our C++ class. Finally, we create a C program that uses a struct EmbClass c pointer to access our C++ EmbClass object dynamically allocated in heap. With the EmbClass c pointer, we set the data member of our C++ EmbClass object, we get the data member's value of our C++ EmbClass object, then print that value to the WSL Ubuntu terminal and finally deallocate the dynamic memory that was allocated for our C++ EmbClass object in the heap.

How to mix C and C++:

Рекомендации по теме
Комментарии
Автор

I don’t use C as much anymore but this is a great refresher it’s awesome James. I like how you teach too. You know what would also be great to review? Real time OS stuff maybe with a widely available controller

christianlopez
visit shbcf.ru