[C++-sig] Re: abstract templates and pyste question.

Hanz Meizer steam at nurfuerspam.de
Tue Feb 17 11:05:21 CET 2004


[...]

>> ----------------------------------------------------
>> template<class T>
>> class PreProcessor
>> {
>> public:
>>   PreProcessor() {}
>>   virtual ~PreProcessor() {}
>>
>>   virtual const int getSize(void) = 0;
>>   virtual T* getObject(int id) = 0;
>> };
>> ----------------------------------------------------
>>
> You have to create a Template, and the instantiate it for the types you 
> want:
> 
> PreProcessor = Template("PreProcessor", "preprocessor.hpp") # here no 
> class is exported yet
> 
> PreProcessor("float", "FPreProcessor")  # instantiate PreProcessor with 
> T=float, and rename the
>                                        # instantiated class to 
> FPreProcessor
> 
> That should do it.
> 
> Regards,
> Nicodemus.

[...]

Unfortunately, this doesn't work. I've even excluded the virtual 
functions like this:
--------------------------------------------------------------------
# PreProcessor.h
PreProcessor=Template("PreProcessor", "TClass.h")
exclude(PreProcessor.getSize)
exclude(PreProcessor.getObject)
PreProcessor_char=PreProcessor("char", "PreProcessor_char")
--------------------------------------------------------------------

I get the following error output:
--------------------------------------------------------------------
pyste.sh  --module=pytest_p pytest_p.pyste
Module pytest_p generated
5.73 seconds
g++ -g -s -I.  -I/home/thomast/work/pyste/boost.current 
-I/usr/include/python2.2  pytest_p.cpp -c -o pytest_p.o
/home/thomast/work/pyste/boost.current/boost/python/object/value_holder.hpp: 
In instantiation of 
`boost::python::objects::value_holder_back_reference<PreProcessor<char>, 
<unnamed>::PreProcessor_char_Wrapper>':
/home/thomast/work/pyste/boost.current/boost/type_traits/alignment_of.hpp:56: 
   instantiated from 
`boost::detail::alignment_of_impl<boost::python::objects::value_holder_back_reference<PreProcessor<char>, 
<unnamed>::PreProcessor_char_Wrapper> >'
/home/thomast/work/pyste/boost.current/boost/python/object/instance.hpp:31: 
   instantiated from 
`boost::alignment_of<boost::python::objects::value_holder_back_reference<PreProcessor<char>, 
<unnamed>::PreProcessor_char_Wrapper> >'
/home/thomast/work/pyste/boost.current/boost/python/object/instance.hpp:31: 
   instantiated from 
`boost::python::objects::instance<boost::python::objects::value_holder_back_reference<PreProcessor<char>, 
<unnamed>::PreProcessor_char_Wrapper> >'
/home/thomast/work/pyste/boost.current/boost/python/object/instance.hpp:47: 
   instantiated from 
`boost::python::objects::additional_instance_size<boost::python::objects::value_holder_back_reference<PreProcessor<char>, 
<unnamed>::PreProcessor_char_Wrapper> >'
/home/thomast/work/pyste/boost.current/boost/python/class.hpp:642: 
instantiated from `void boost::python::class_<T, X1, X2, 
X3>::register_holder() [with T = PreProcessor<char>, X1 = 
boost::noncopyable, X2 = <unnamed>::PreProcessor_char_Wrapper, X3 = 
boost::python::detail::not_specified]'
/home/thomast/work/pyste/boost.current/boost/python/class.hpp:275: 
instantiated from `boost::python::class_<T, X1, X2, X3>::class_(const 
char*, const boost::python::init_base<DerivedT>&) [with DerivedT = 
boost::python::init<boost::mpl::void_, boost::mpl::void_, 
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, 
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, 
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, 
boost::mpl::void_, boost::mpl::void_, boost::mpl::void_, 
boost::mpl::void_>, T = PreProcessor<char>, X1 = boost::noncopyable, X2 
= <unnamed>::PreProcessor_char_Wrapper, X3 = 
boost::python::detail::not_specified]'
pytest_p.cpp:41:   instantiated from here
/home/thomast/work/pyste/boost.current/boost/python/object/value_holder.hpp:59: 
error: cannot
    declare field `
    boost::python::objects::value_holder_back_reference<PreProcessor<char>,
    <unnamed>::PreProcessor_char_Wrapper>::m_held' to be of type `
    <unnamed>::PreProcessor_char_Wrapper'
/home/thomast/work/pyste/boost.current/boost/python/object/value_holder.hpp:59: 
error:
     because the following virtual functions are abstract:
TClass.h:72: error:     const int PreProcessor<T>::getSize() [with T = char]
TClass.h:73: error:     T* PreProcessor<T>::getObject(int) [with T = char]
make: *** [pytest_p.o] Error 1
--------------------------------------------------------------------

As far as I understand it, the compiler expects that the template can be 
instantiated. Looking into the pytes_p.cpp (which was generated with pyste):

     class_< PreProcessor<char>, boost::noncopyable, 
PreProcessor_char_Wrapper >("PreProcessor_char", init<  >())

Shouldn't this read no_init? I'm confused :(

Greetings,
H.





More information about the Cplusplus-sig mailing list