partial template specialization
Hi All,
Can you help me with a problem i have with a partial template
specialization, let's say i want to specialize template AB for a
container sdt::deque or any other. Is there any way to have all
methods and properties from 'general' AB and to specialize only
ONE method ? I think i coud do that using multiple inheritance,
is
there any other way ?
----------------------------------------- FILE
--------------------------------------------------------------------------------------
#include <vector>
#include <deque>
#include <iostream>
using namespace std;
template<class T, template <class,class> class Cont , typename Alloc =
allocator<T> >
class AB{
public:
typedef typename Cont<T,Alloc> tCont;
tCont buf;
void write(T & el){
cout << "general" << endl;
buf.push_back(el);
}
void read(T & el){
el = buf.last();
}
};
template<class T,class Alloc
class AB<T,std::deque,Alloc>{
public:
void write(T & el){
cout << "specialized" << endl;
std::deque<T,Alloc> buf;
buf.push_front(el);
}
};
class A{
public:
~A(){ cout<< "destructor" << endl;} };
int _tmain(int argc, _TCHAR* argv[])
{
AB<A,std::vector> Buf;
A b;
Buf.write(b);
Buf.read(b);
AB<A,std::deque> Buf2;
A c;
Buf2.write(c);
Buf2.read(c);
}
//------------------------------------------
EOF-------------------------------------------------------------------------------------------------
Thanks in advance,
Tomek
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]