I am using SWIFT_SHARED_REFERENCE so swift maps the C++ Classes to Reference Type not to value types (default behaviour).
C++ Class Skeleton
class CppClass{
public:
CppClass () {
uValue = 0;
}
CppClass (int pValue) {
uValue = pValue;
}
void SetValue (int pValue) noexcept;
// Method which is Invoked by Swift.
static CppClass& ReturnObj () noexcept;
static void PassObj() noexcept;
public:
int uValue;
}SWIFT_SHARED_REFERENCE(RetainObject, ReleaseObject);
Return Object:
CppClass&
CppClass::ReturnObj() noexcept
{
static CppClass obj;
std::cout << obj.vValue << std::endl;
return obj;
}
Swift Code:
var x = CppClass.ReturnObj()
// Operate on x
The above code works. But when I try to Instantiate Object in Swift .
Swift Code:
var x = CppClass (uValue : 20)
I am getting the error:
'CppClass' cannot be constructed because it has no accessible initializers.