I've been running this one over in my head all weekend.  And to tell you the truth, it 
bothers me.

HtVector and HtHeap both inherit Object.  Object defines the member Copy() as a 
virtual function with a return type of Object* (htlib/Object.h:43).  

virtual Object* Copy() const { fprintf(stderr, "Object::Copy: derived class does not 
implement Copy\n"; return new Object(); }

HtVector and HtHeap both implement Copy() as HtVector* Copy and HtHeap* Copy 
respectively.  To me, that seems VERY wrong.  Sparc C seems to agree with me as well, 
giving me a hard error in compilation.

I have a solution I'd like to propose that would resolve the issue but might break 
something else and I'd like to hear some feedback on it.

What if we made Object a template class like the following:

template <class T> class Object {
        public:
                Object() {}
                virtual ~Object() {}

                virtual int compare(const T&) const = 0;

                virtual T       *Copy() const   { return NULL; }
};

The only problem with this is that we'd lose the method (htlib/Object.h:37)
        virtual int compare(Object &) const;

Now one line of code that bothers me SEVERELY is in (htlib/htString.h:109)

        int compare(const Object& s) const { return compare((const String&)s); }

There is NO checking to see if Object is infact a string just a blind cast to a String 
reference.  THAT is dangerous to say the least.  By losing the very loose function 
compare at htlib/Object.h:37 we'll gain templatized type safety.

Can anyone tell me a reason why we could not just ditch the virtual compare method I 
mentioned above and switch to a template?

Thanks guys & gals.
--
David J. Graff
Broadvision/Atlanta -  Principal Consultant
mailto:[EMAIL PROTECTED]
Phone: (678) 427-5412
This message is intended only for the use of the Addressee and may contain information 
that is PRIVILEGED and CONFIDENTIAL. If you are not the intended recipient, 
dissemination of this communication is prohibited. If you have received this 
communication in error, please erase all copies of the message and its attachments and 
notify us immediately.

_______________________________________________
htdig-dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/htdig-dev

Reply via email to