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
{{ message }}
Repository navigation
GDCLASS macro prohibits use of pure virtual functions #1287
When trying to create a GDExtension abstract class, the compiler fails to allow pure virtual functions, reporting:
error C2259: 'ParentClass': cannot instantiate abstract class
This is because the GDCLASS macro explicitly makes two references to where it attempts to create the class object, specifically in these two static methods:
The ability to use GDCLASS in GDNative and construct abstract classes exists. I would suggest that GDCLASS function like it does in GDNative and these two specific methods be added to either a separate macro or we introduce a new GDCLASS_ABSTRACT macro that can be used specifically for abstract class construction with all but the above 2 functions defined.
Since Godot modules can register abstract classes, we want to allow godot-cpp to do so as well. However, we also want to try to mimic the module API as much as possible, and in a module, you can use GDCLASS() for both normal and abstract classes. So, ideally, we'd like the same GDCLASS() macro to be used for both in godot-cpp as well (as opposed to adding a GDCLASS_ABSTRACT() macro).
Maybe there's a way to move the generation of the create() and recreate() functions to templates that are only realized when calling ClassDB::register_class<T>()?
@dsnopek So I see that _GDCLASS_RECREATE takes the parent class type; however, it isn't used in the macro. Are you okay with simply having the macro accept the m_class argument only?
Is there some sort of if constexpr we could use to check if the class has pure virtual functions?
Otherwise I wonder why create would have to be in the class, if it can be moved out that would be better I think
Activity
dsnopek commentedon Oct 26, 2023
Thanks!
This is a tricky one.
Since Godot modules can register abstract classes, we want to allow godot-cpp to do so as well. However, we also want to try to mimic the module API as much as possible, and in a module, you can use
GDCLASS()for both normal and abstract classes. So, ideally, we'd like the sameGDCLASS()macro to be used for both in godot-cpp as well (as opposed to adding aGDCLASS_ABSTRACT()macro).Maybe there's a way to move the generation of the
create()andrecreate()functions to templates that are only realized when callingClassDB::register_class<T>()?Something like this super incomplete psuedo code:
And then when registering abstract classes, we wouldn't use that, we'd just use
nullptrfor the creation function.Hopefully that idea makes sense :-)
Naros commentedon Oct 27, 2023
@dsnopek So I see that
_GDCLASS_RECREATEtakes the parent class type; however, it isn't used in the macro. Are you okay with simply having the macro accept them_classargument only?Zylann commentedon Oct 28, 2023
Is there some sort of
if constexprwe could use to check if the class has pure virtual functions?Otherwise I wonder why
createwould have to be in the class, if it can be moved out that would be better I thinkAThousandShips commentedon Oct 28, 2023
There is
std::is_abstractMerge pull request #1359 from Naros/GH-1287