Accesing inherited C++ library functions from C - c++

I need to link my c-program with functions from inherited c++ library. The standard way is to use c++ wrappers to define a dummy c-structure that represents the c++ class. That works for simple (not inherited) classes. How can I modify it to work with inherited classes (i.e. air->cloud->lightning)?
Simple case:
typedef struct lightning lightning;

Related

How to extend C++ classes from Terralang?

Is there a way to embed terralang into a C++ application, such that C++ classes can be extended from terra, including overloading virtual functions?
BONUS: Can this be done (semi?)automatically for a (large)set of classes, without needing to write "wrapper code" for each class and each virtual method?

Does Boost.Python need binding code for other boost libraries?

I have a class that inherits from boost::statechart library. I need to use this class in Python script, I am wondering if I need to write wrapper codes (.def s) for all boost::statechart library just because my class inherited from it? Or the boost.python will not need any wrapper code to see the definitions (it handles other boost libraries automatically to call in python)?
Boost.Python does not have any special handling for Boost classes. If you want to use inherited functions (Boost class or not), you need to expose them to Python like you would do with your own code.
If you don't want to use any of the base class functions from your script, you need not do anything besides binding your own code.
You have two options if you need (some of) the base class interface available from Python:
You bind the base class separately and expose it as a base for your class. This is the most "complete" solution (as complete as you make it - you can choose to limit the number of exposed functions).
You don't bind the base class. Python does not have to know about the inheritance relationship. You can simply bind the functions you want to expose as all public functions are members of the derived class, too. This is simpler if you only need some of the base class functionality to be usable from Python.

C++ functions in Objective C

I am getting a bit confused how to call C++ functions in Objective C.
I've declared my functions as:
void InitializeSearchRegistration();
In the header file in between the interface and end. I've then defined it in my mm file as:
void InitializeServiceRegistration()
{
}
What I am struggling with is how to define it as public to ensure other classes can see it. I've tried public but get an error. Usually C++ methods have to be declared in a class block.
Any advice would be great.
You can't add C++ member functions to an Objective-C class using Objective-C++. You should consider redesigning your class to either have a totally C++ interface (in which case it should be a C++ class or struct) or a totally Objective-C interface (in which case it should define ObjC class and instance methods, not C++ member functions).
There are two ways to go about this, the first is to combine C++ and Objective C into another language, called Objective C++. The other is to communicate over plain C functions.

Returning pointer to unmanaged class from C++/CLI wrapper which can be imported into C#

I have a C++ class that I need to create several instances of in a C# application. Apparently this means I'll need to make a C++/CLI wrapper as you can't import C++ classes into C#, but I've never used it before. The C++ class inherits from a base class which just contains several pure virtual functions, and no data. The DLL exports just one function which creates a new instance of the class and returns a pointer to the base class.
What C++/CLI type can be used to call that function and get the pointer to the C++ class, but which can also be imported into C#?
Thanks.
You don't need any special “C++/CLI type”, you should be able to call that function like from normal C++. But if you want to use the C++ class from C#, you really need to write C++/CLI managed wrapper class that you will be able to use from C#.
The managed wrapper class will contain a filed with a pointer to the unmanaged class. It will also contain the same members as the unmanaged class, that forward to their unmanaged equivalents.
For an example of how to do that, see How to: Wrap Native Class for Use by C# on MSDN.

C structure and C++ structure

Could anybody please tell me what is the main difference
between C & C++ structures.
In C++ struct and class are the exact same thing, except for that struct defaults to public visibility and class defaults to private visiblity.
In C, struct names are in their own namespace, so if you have struct Foo {};, you need to write struct Foo foo; to create a variable of that type, while in C++ you can write just Foo foo;, albeit the C style is also permitted. C programmers usually use typedef struct {} Foo; to allow the C++ syntax for variable definitions.
The C programming language also does not support visibility restrictions, member functions or inheritance.
In C++, structures behave like classes, allowing methods, constructors, destructors etc...
The main difference between classes and C++ structures is that everything inside structures is public by default, while everything inside classes is private by default. (ie: nothing outside can access them directly)
There are several differences in C and C++ structure
In C we define struct keyword is necessary to create the structure type value while in C++ it is not necessary.
In C there is no function inside the structure while in C++ we can define function that can access the data members of structure directly( Function is names as method in C++ )
There is no concept of access modifier inside the structure in C while in C++ we can find the access modifier (eg. private and public ). By default all are public.
Structure in C can not have static members while in C++ structure can have static members.
Size of empty structure is constraint violation in C, but it is always 1 in C++.
We can have both pointers and references to struct in C++, but only pointers to structs are allowed. (References aren't feature of C language)
C structs is more akin to a definition of a composite data structure
C++ structs can be thought of as a class but scope of all member variables are defaulted to public.
In addition to the answers above, remember that C++ structures support inheritance and so can contain pointers to vtables. This can make a big difference when serializing and deserializing these structures across processes. Templates are supported too.
C : we can't define function inside the structure in c.
C++ : We can define function inside the structure in c++.