Thomas Maier-Komor wrote:
> Kai-Uwe Bux wrote:
>> Thomas Maier-Komor wrote:
>>
>>
>>>Hi everybody,
>>>
>>>I am a little bit confused with the syntax of explicit instantiation,
>>>and I am not sure that it is possible to do what I want to do.
>>>Maybe someone has an idea.
>>>
>>>Consider a template class:
>>>
>>>template <class ABC>
>>>struct CT : public ABC
>>>{
>>>template<typename T>
>>>void a(T const &)
>>>{
>>>// something
>>>}
>>>
>>>// the next line is not enough for what I want, but probably needed
>>>using ABC::a;
>>>};
>>
>>
>> Why is this needed?
>>
>>
>>>//... and an abstract base class:
>>>
>>>struct ABC
>>>{
>>>virtual void a(int const &) = 0;
>>>};
>>>
>>>//... and a usage:
>>>
>>>struct MyClass : public CT<ABC>
>>>{
>>>
>>>};
>>>
>>>
>>>now CT<>::a hides ABC::a. But I would like to instantiate CT::a
>>>so that it does not hide ABC::a, but implement the virtual
>>>function ABC::a for MyClass.
>>>
>>>Is this possible? what do I have to write into MyClass?
>>>Any idea?
>>>
>>>
>>>Tom
>>
>>
>> I am not sure whether this is legal, but on my machine it appears to do
>> the intended:
>>
>>
>>
>> #include <iostream>
>>
>> struct A {
>>
>> virtual void a ( void ) = 0;
>>
>> virtual ~A ( void ) {}
>>
>> };
>>
>> template < typename T >
>> struct B : public T {
>>
>> void a ( void ) {
>> std::cout << "hello world!\n";
>> }
>>
>> ~B ( void ) {}
>>
>> };
>>
>> struct C : public B<A> {
>>
>> void a ( void ) {
>> std::cout << "don't say hello!\n";
>> }
>>
>> ~C ( void ) {}
>>
>> };
>>
>> struct D : public B<A> {
>>
>> ~D ( void ) {}
>>
>> };
>>
>>
>> int main ( void ) {
>> A * a_ptr = new C;
>> a_ptr->a();
>> A * a2_ptr = new D;
>> a2_ptr->a();
>> }
>>
>>
>>
>> Best
>>
>> Kai-Uwe Bux
>
>
> OK that's obvious, but this does not employ my
> template method, which should implement the pure
> virtual method automagically. And _that_ is my
> primary intention...
Clearly, I just do not understand what you are trying to accomplish. How is
the pure virtual method A::a not automatigically implemented in the class D
from my example? A::a clearly is implemented in D, and it is implemented
via inheriting from the template B<A>.
Sorry for not being helpful
Kai-Uwe Bux
|