Re: pure virtual function in template class
On Thu, 10 Jul 2008 05:53:45 -0700, puzzlecracker wrote:
On Jul 10, 8:49 am, Mike -- Email Ignored <m_d_berger_1...@yahoo.com>
wrote:
Is a pure virtual function in allowed in a template base class? In any
case, I have one working. Am I skating on thin ice?
Thanks,
Mike.
Yes, it can be in the template class, but it can NOT be a virtual
template member function
I don't understand how it could be pure, but not a member.
In any case, here is code that works on my system showing
exactly what I mean.
Mike.
// virt_temp.cc 07/10/08
#include <iostream>
using namespace std;
template <class TYP>
class BaseT
{
protected:
BaseT(TYP x,TYP y) : x_(x),y_(y){}
void doAll(){cout << "x_="<<x_<<',';doChild(y_);cout<<endl;}
virtual void doChild(TYP a)=0;// pure virtual member function
private:
TYP x_;
TYP y_;
};
class Child : protected BaseT<int>
{
public:
Child() : BaseT<int>(1,2){}
void doThings(){doAll();}
private:
virtual void doChild(int a);
};
void Child::doChild(int a){cout<<"a="<<a;}
int main(int argc, const char* argv[])
{
Child child;
child.doThings();
}