Default arguments in extern cppclass

23 views
Skip to first unread message

Source

unread,
Feb 11, 2025, 12:15:14 AMFeb 11
to cython-users
Hey.

I have rewritten most, or well about half, of the code in my main project in C++.

And I'm getting the error during compilation:
standalone.cpp: In function ‘void __pyx_f_10standalone_loadPlayerData(std::string)’:
standalone.cpp:32482:54: error: aggregate ‘__pyx_f_10standalone_loadPlayerData(std::string)::__pyx_opt_args_12basecreature_loadInventory __pyx_t_35’ has incomplete type and cannot be defined
32482 |   struct __pyx_opt_args_12basecreature_loadInventory __pyx_t_35;

This use case seems undocumented in the Cython docs, namely it talks about overloading C++ functions, but that method doesn't work for C++ class methods.

For example if I write in my extern from cppclass nogil class:
void loadInventory() nogil
void loadInventory(bool init) nogil

Or the other way around both, I will get a cython error complaining about expecting an argument when there are 0 arguments.

If I just do:
void loadInventory(bool init = True) nogil

Then I will get this compilation error.

Not sure why it happens; it doesn't happen with all the methods, but many of them, and only methods with default arguments it looks like.

I also tried bool init = * and that gave a Cython syntax error.

What's the right way to proceed?

da-woods

unread,
Feb 11, 2025, 3:16:52 AMFeb 11
to cython...@googlegroups.com

Non-extern cppclass is pretty limited, so I'm not really surprised that i doesn't work.

Most of the C++ wrapping is done from the point of using existing C++ code (where overloaded methods work) rather than trying to generate new C++ classes from Cython.

--

---
You received this message because you are subscribed to the Google Groups "cython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cython-users...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/cython-users/169f2e09-7151-4681-b67a-045aa4daf3c6n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages