On Nov 29, 2007 1:10 AM, Patrick Hartling
<pat...@pr...> wrote:
> We have run into a problem with code generated by Py++ involving
> pointers to member templates. For example, consider this class:
>
> class C
> {
> public:
> template<typename T>
> T getValue() const
> {
> return static_cast<T>(mValue);
> }
>
> private:
> int mValue;
> };
>
> The code generated by Py++ to expose C::getValue() will include
> something similar to the following:
>
> typedef int (C::* ptr_type)() const;
> ptr_type p = ptr_type(&C::getValue);
>
> The above does not compile with Visual C++ 7.1, though it does compile
> with 8.0 and 9.0. For Visual C++ 7.1, the following syntax must be used:
>
> typedef int (C::* ptr_type)() const;
> ptr_type p = ptr_type(&C::getValue<int>);
>
> While I do not have a deep familiarity with the C++ standard,
> including the template parameter in the pointer-to expression is what
> I would try to write if I were coding this up manually. Is the second
> form incorrect or just unnecessarily verbose?
>
> Given that the pointer-to expression without the template parameter
> does compile with newer versions of Visual C++, I have to think that
> this is a bug in or a limitation of Visual C++ 7.1. If including the
> template parameter in the pointer-to expression is valid, could a
> change be made to Py++ to include that extra information so that the
> code it generates can be built with Visual C++ 7.1?
I am aware of this problem and Py++ already contains functionality to solve it.
Next code should solve the issue:
mb = module_builder_t( ... )
f = mb.mem_fun("C::getValue")
f.alias = f.name #use short, user friendly name
f.name = f.demangled_name #set name that compiler understands
#you need this if you don't use latest SVN version of Py++ and pygccxml
f.create_with_signature = True
The problem is that GCCXML reports C::getValue as is, instead of
C::getValue<int>, so Py++ uses magled name of the function to extract
the real name.
P.S. Before I make this behavior to be default, I prefer to get
feedback from the users, whether it works fine or not in all their
use-cases.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|