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
I have such a thing
class cLoader : public cDataObject<T>
So when I instantiate it, I used
ldr = cLoader();
Huh? Don't you mean
cLoader ldl = cLoader();
or somesuch? Anyhow, cLoader is not a class/type but a template for a class,
so you must instantiate it:
cLoader<int> lrd = cLoader<int>();
which would then be correct C++. However, and there is some work to do for
your brain, this is Java code, while we're in C++. Therefore:
Lastly, I doubt it is a good idea to say that a loader is a data object.
That is a very twisted use of inheritance. Often, loading is a function and
also better expressed as one. In particular if there is a source object and
a target object, a simple function that mediates between both is often
clearer and better extendable than drilling into either type via
inheritance. Again, this is C++ and not Java which tries to force you to
apply the OOP hammer to every problem even if it is not an OO nail.
then I have heaps of methods in this class, do I have to add <T> in each
No, the methods are part of the class and deduced correctly by the final
type. Get a good C++ book from the reviews at http://accu.org.