Hi,
I am trying to pass the pointer of class defined by me in swift from swift to C++. In the documentation it's mentioned that
QUTOE
Any function, property, or initializer is exposed to C++ only when Swift can represent all of its parameter and return types in C++. A parameter or return type can be represented in C++ only when:
- it is a supported Swift structure / class / enumeration that is defined in the same Swift module.
- or, it is a C++ structure / class / enumeration that is not annotated as a reference type.
- or, it is one of the supported Swift standard library types.
- if it’s a generic type, like
Array
, its generic parameters must be bound to one of the types listed here.
- if it’s a generic type, like
- or, it is an
UnsafePointer
/UnsafeMutablePointer
/Optional<UnsafePointer>
/Optional<UnsafeMutablePointer>
that points to any type from the supported three type categories listed above.
UNQUOTE
Under the Section - Swift Functions and Properties Supported by C++
Here's the code which I have written.
Swift Code:
public class MyClass {
public init (_ pValue : Int32) {
uValue = pValue
}
public var uValue : Int32
}
// Allocating the pointer
var pointer = UnsafeMutablePointer<MyClass>.allocate(capacity: MemoryLayout<MyClass>.size)
// Function which is called by C++ and it returns the pointer allocated.
public func ReturnMyClassPointer () -> UnsafeMutablePointer<MyClass> {
return pointer
}
// Function called by c++ to deallocate.
public func ReleasePointer (_ pPtr : UnsafeMutablePointer<MyClass>) {
pPtr.deallocate()
}
// InvokeC code .
Interop::InvokeC ()
C++ Code
void
CppClass::InvokeC()
{
Test_Interop::MyClass * ptr = Test_Interop::ReturnMyClassPointer ();
Test_Interop::ReleasePointer (ptr);
}
I am getting this build error:
No member named 'ReturnMyClassPointer' in namespace 'Test_Interop'
How can I do this?