Здравствуйте коллеги, знаю что нельзя явно определить шаблонную функцию виртуальной, но хотелось бы получть что то типа такого
class A
{
public:
A(){}
virtual ~A(){std::cout <<"~A()";}
template<class _TAggrKey, class _TMemSet>
bool LoadBTreeNode(_TMemSet& Set)
{std::cout <<"A::LoadBTreeNode"; return true;}
virtual int size() const = 0;
};
class B : public A
{
public:
B(){}
virtual ~B( ){std::cout <<"~B()"; }
template<class _TAggrKey, class _TMemSet>
bool LoadBTreeNode(_TMemSet& Set)
{
std::cout <<"B::LoadBTreeNode";
_TAggrKey key;
key = 12;
Set.insert(key);
}
virtual int size() const
{
return 1;
}
};
class C : public A
{
public:
C(){}
virtual ~C( ){std::cout <<"~C()"; }
template<class _TAggrKey, class _TMemSet>
bool LoadBTreeNode(_TMemSet& Set)
{
std::cout <<"C::LoadBTreeNode";
_TAggrKey key;
key = 18;
Set.insert(key);
key = 22;
Set.insert(key);
}
virtual int size() const
{
return 2;
}
};
///////////////////////////////////////
A *pB = 0;
A *pC = 0;
pB = new B();
pC= new C();
std::set<int> setI;
std::set<float> setF;
pB->LoadBTreeNode<int, std::set<int> >(setI);
pC->LoadBTreeNode<float, std::set<float> >(setF);
delete pB;
delete pC;
В моем примере естественно происходит вызов методов класса A, но можно ли как то "перегрузить", что бы через указатель базового классы вызывался шаблонный метод потомка?