Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow virtual function for DEFINE_FIELD #117

Open
oruebel opened this issue Dec 22, 2024 · 0 comments
Open

Allow virtual function for DEFINE_FIELD #117

oruebel opened this issue Dec 22, 2024 · 0 comments
Labels
category: enhancement proposed enhancements or new features priority: low alternative solution already working and/or relevant to only specific user(s)

Comments

@oruebel
Copy link
Contributor

oruebel commented Dec 22, 2024

See discussion at #85 (comment)

Currently DEFINE_FIELD in RegisteredType.h creates a templated member function. However, when "redefining" a field in a child class B with DEFINE_FIELD the existing member function that was inherited from the base class A is being "hidden" instead of "override". This is fine if we are using a pointer of type B. However, if we cast the pointer to the base class A, then the definition of the function from A is being used since the member function is not virtual. However, C++ does not allow virtual templated functions.

Here the corresponding note in the docs (which should be updated when this issue is being addressed):

* \note
* ``DEFINE_FIELD`` creates templated, non-virtual read functions. This means if we
* want to "redefine" a field in a child class by calling ``DEFINE_FIELD`` again, then
* the function will be "hidden" instead of "override". This is important to remember
* when casting a pointer to a base type, as in this case the implementation from the
* base type will be used since the function created by ``DEFINE_FIELD`` is not virtual.

@oruebel oruebel added category: enhancement proposed enhancements or new features priority: low alternative solution already working and/or relevant to only specific user(s) labels Dec 22, 2024
@oruebel oruebel mentioned this issue Dec 22, 2024
70 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: enhancement proposed enhancements or new features priority: low alternative solution already working and/or relevant to only specific user(s)
Projects
None yet
Development

No branches or pull requests

1 participant