[C++-sig] Re: abstract templates and pyste question.
Nicodemus
nicodemus at esss.com.br
Wed Feb 18 16:36:12 CET 2004
David Abrahams wrote:
>Nicodemus <nicodemus at esss.com.br> writes:
>
>
>>Hanz Meizer wrote:
>>
>>
>>>[...]
>>>
>>>
>>>>>----------------------------------------------------
>>>>>template<class T>
>>>>>class PreProcessor
>>>>>{
>>>>>public:
>>>>> PreProcessor() {}
>>>>> virtual ~PreProcessor() {}
>>>>>
>>>>> virtual const int getSize(void) = 0;
>>>>> virtual T* getObject(int id) = 0;
>>>>>};
>>>>>----------------------------------------------------
>>>>>
>>>>>
>>>I get the following error output:
>>>--------------------------------------------------------------------
>>>
>>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
>>
>>>>error--------------------------------------------------------------------
>>>>
>>>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 :(
>>>
>
>There are two choices:
>
> 1. It can be no_init
>
> 2. PreProcessor_char_Wrapper must define getSize() and getObject()
>
>Clearly, whatever was generated by pyste does neither of these.
>
The Wrapper defines getSize() and getObject(), but not no_init, and this
compiles under msvc 6.0. But if we define no_init, then it's not
possible to subclass PreProcessor from Python:
>>> import temp
>>> class C(temp.PreProcessor_float):
... def getSize(self): return 1
... def getObject(self): return self
...
>>> c = C()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
RuntimeError: This class cannot be instantiated from Python
>>>
So what should we do in this case?
More information about the Cplusplus-sig
mailing list