You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/cxx-interop/index.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1282,7 +1282,8 @@ let object = SharedObject(42)
1282
1282
1283
1283
Note that if a C++ constructor and a user-annotated static factory (using `SWIFT_NAME`) have identical parameter signatures, Swift favors the static factory when resolving initializer calls.
1284
1284
This is particularly useful when you want to use a custom allocator or want to disable direct construction entirely and expose only factories.
1285
-
### Inference of Shared Reference behaviour in Derived Types
1285
+
1286
+
#### Inference of Shared Reference behaviour in Derived Types
1286
1287
1287
1288
When a C++ type inherits from a `SWIFT_SHARED_REFERENCE` base type, the Swift compiler automatically infers `SWIFT_SHARED_REFERENCE` annotation for the derived type.
1288
1289
The derived type also gets imported as a reference type, and uses the same `retain` and `release` functions as its base class.
@@ -1322,7 +1323,7 @@ unOwned.doSomething()
1322
1323
Note that the Swift compiler will automatically infer the ownership conventons for Swift functions returning `SWIFT_SHARED_REFERENCE` types.
1323
1324
See [Exposing C++ Shared Reference Types back from Swift](#exposing-c-shared-reference-types-back-from-swift) for calling Swift functions returning `SWIFT_SHARED_REFERENCE` types from C++.
1324
1325
1325
-
### Calling conventions when passing Shared Reference Types from Swift to C++
1326
+
####Calling conventions when passing Shared Reference Types from Swift to C++
1326
1327
1327
1328
If a C++ shared reference type is passed as an argument to a C++ API from Swift, the Swift compiler guarantees that the passed value would be alive.
1328
1329
Swift also retains the ownership of the value.
@@ -1360,15 +1361,15 @@ However, the C++ function is responsible for releasing the old value, and ensuri
1360
1361
Adhering to these rules is necessary to safely and correctly pass around `SWIFT_SHARED_REFERENCE` between Swift and C++.
1361
1362
These rules are also generally recommended conventions to manage shared objects that use reference counting.
1362
1363
1363
-
### Inheritance and Virtual Member Functions
1364
+
####Inheritance and Virtual Member Functions
1364
1365
1365
1366
Similar to value types, casting an instance of a derived reference type to a
1366
1367
base reference type, or vice versa, is not yet supported by Swift.
1367
1368
1368
1369
If a reference type has virtual methods, you can call those methods from Swift.
1369
1370
This includes pure virtual methods.
1370
1371
1371
-
### Exposing C++ Shared Reference Types back from Swift
1372
+
####Exposing C++ Shared Reference Types back from Swift
1372
1373
1373
1374
C++ can call into Swift APIs that take or return C++ Shared Reference Types. Objects of these types are always created on the C++ side,
1374
1375
but their references can be passed back and forth between Swift and C++. This section explains the conventions of incrementing and decrementing
0 commit comments