[QUESTION] How to cast an internal member variable type? #3518
softempire
started this conversation in
General
Replies: 2 comments
-
I know I can change the type for data to EType. But if the class is written by other people and I can't change it. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I found we can use (EType A::*)(&A::data). It works |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi There,
I have a class
class A
{
public:
int data;
}
enum EType
{
TypeA = 0,
TypeB
}
I want to expose data as EType, how can I do this? Does pybind have a cast function?
def_readwrite("data", &A::data) will return an int value.
I can define a property
def_property("data",
[](A& inst)
{
return static_cast(inst.data);
},
[](A& inst, EType newData)
{
inst.data = static_cast(newData);
}
but it looks not good enough.
Beta Was this translation helpful? Give feedback.
All reactions