How do I create a C++ class that Swift can interop with that has a destructor? For example:
// C++
namespace Name {
class Foo
{
public:
Foo() = default;
Foo(uint32_t i); // implemented in .cpp file
~Foo(); // implemented in .cpp file
};
}
// Swift
import cxxLib
let bar = Name.Foo(2)
Writing this code gives me an error:
main.swift: error: 'Foo' is unavailable: non-trivial C++ class with trivial ABI is not yet available in Swift
let bar = Name.Foo(2)
^~~
__ObjC.cv:3:19: note: 'Foo' has been explicitly marked unavailable here
public struct Foo {
^
When I remove the destructor, the code works fine. Classes in the C++ standard library can be used if a type alias is created for the template, and these class must have destructors to free memory, so how can I acheive this?
I am using windows, swift version 5.10