I have a common problem to write a C++ wrapper for a C library… my main storage a C-Struct pointers who represent always a C++ class containing just ONE data filed.
class MyClassC {
struct MyStructS * hdl
...
}
creating all the constructors, static and method function is NO problem… my design problem is right now… should I use a value class design or a pointer class design.
value class always return the object and NOT the pointer:
a value class has a ONE to MANY relationship between MyStructS and MyClassC
MyClassC myMethod () {
...
return MyClassC(struct MyStructS *...);
}
Destructor of a value class never free the struct MyStructS pointer and is mostly empty
Destructor of a value is an static or method mainly called destry or delete
MyClassC::delete() {
DestroyMyPointer(&hdl)
}
...
MyClassC obj = {...};
...
obj.delete();
...
a value class is the argument on methods a value as well:
some_proc_or_method (MyClassC arg1, MyClassC arg2, …) {
...
}
and there is an other question:
how do i create default arguments for a value class argument?
some_proc_or_method (MyClassC arg1, MyClassC arg2 = MyClassC {...} ???? ) {
...
}
pointer class always return the pointer of the object:
a pointer class has a ONE to ONE relationship between MyStructS and MyClassC
MyClassC* myMethod () {
...
return this or getThisFrom(myStructS_pointer)
}
Destructor of a pointer class always free the struct MyStructS pointer
~MqClassC () {
DestroyMyPointer(&hdl)
}
...
MyClassC* obj = new MyClassC(...);
...
delete obj;
...