[C++-sig] [Py++] incomplete type and forward declaration

Roman Yakovenko roman.yakovenko at gmail.com
Sun May 31 06:27:43 CEST 2009

On Fri, May 29, 2009 at 1:20 PM, Werner Joergensen
<wjoergensen at yahoo.com> wrote:
> How can I process such a file classA.hpp using a code generator like http://www.language-binding.net/pyplusplus/documentation/tutorials/module_builder/generate_code.py.html?
> ----------8<---- classA.hpp ------
> class B;
> class A{
> public:
>  B& dontCareAboutB(){ /*return C::getB();*/ };
>  void doSomething(){};
> };
> ----------8<----------
> This class compiles fine with just "g++ -c classA.hpp", but applying the pyplusplus code generator followed by bjam throws several errors:
> ...
> /opt/boost_1_39_0/boost/python/type_id.hpp:89: error: invalid use of incomplete type ‘struct B’
> ./classA.hpp:1: error: forward declaration of ‘struct B’
> ...
> If I replace the first line with "class B{}", making B a comple, empty class, this example succeeds. But then I run into more troubles if I add the actual definition of the real class B from another header file to the python module.
> Does a solution with pyplusplus exist, where I don't need to modify the classA.hpp header file?

I think, the solution exists. First of all you should understand, that
Boost.Python really needs to know( see definition ) of class B. So you
will have to include it "before" the generated code.

What you can do is to add the "B" header file to class A generate
code:  http://language-binding.net/pyplusplus/documentation/inserting_code.html#header-files


Roman Yakovenko
C++ Python language binding

More information about the Cplusplus-sig mailing list