Skip to content

Commit

Permalink
add paragraph on struct/union
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Mar 12, 2022
1 parent 13224e6 commit 3ded28c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions doc/source/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,44 @@ behave as expected:
.. _sec-operators-label:


`Structs/Unions`
----------------

Structs and unions are both supported, named or anonymous.
If the latter, the field are accessible through the parent scope by their
declared name.
For example:

.. code-block:: python
>>> cppyy.cppdef("""\
... struct PointXYZ {
... PointXYZI() : intensity(5.) {}
... double x, y, z;
... union {
... int offset1;
... struct {
... int offset2;
... float intensity;
... };
... float data_c[4];
... };
... };""")
True
>>> p = cppyy.gbl.PointXYZI()
>>> type(p.x)
<class 'float'>
>>> p.intensity
5.0
>>> type(p.data_c[1])
<class 'float'>
>>> p.data_c[1] = 3.0
>>> p.intensity
3.0
>>>
`Operators`
-----------

Expand Down

0 comments on commit 3ded28c

Please sign in to comment.