home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!agate!doc.ic.ac.uk!sot-ecs!tpm
- From: tpm@ecs (TP Monks)
- Newsgroups: comp.lang.c++
- Subject: ambiguity in subclass
- Message-ID: <13997@ecs.soton.ac.uk>
- Date: 17 Dec 92 11:21:16 GMT
- Sender: news@ecs.soton.ac.uk
- Lines: 55
- Nntp-Posting-Host: elstar
-
-
- I've run into a problem where I'm not quite sure how to implement something.
-
- I wanted to implement a set of classes using templates which have a
- set of member functions like this:
-
- template<class T> struct bill {
- bill() {}
- T& operator*(T);
- T& operator+(T);
- T& operator-(T);
- T& operator/(T);
- }
-
- These are used to implement some arithmetic and other operations on
- small arrays. I wish to create a well known set of subclasses which
- further overload these operations:
-
- struct ted : public bill<float> {
- ted() {}
- ted& operator*(bogus);
- }
- struct bogus : public bill<short> {
- bogus() {}
- bogus& operator*(ted);
- }
-
- Of course, this can't be done because, because of ambiguity:
- ted t;
- ted t1=t*.1; // error, operator*(float) is hidden
-
- I could get round it by using:
- ted t1=t.bill<float>::operator*(.1); // ok
- But lets face it, its just not the same.
-
- I could also get round it by adding another member fn to bill and ted
- along the lines of:
- inline ted& ted::operator*(float a) { return bill<float>::operator*(a);}
- I could go further and implement *,+,-,etc using macros but surely this
- is clumsy and must be unecessary.
-
- Please tell me if there is something fundamentally wrong with my thinking.
- (Please *don't* tell me if I forgot a ; or something!!!)
- If there isn't, surely what I am doing is a common problem. In this
- case, what is the best way to solve this problem and implement my classes?
-
- Help!
-
- Tim
-
- --
- -----------------------------------------------------------------------------
- Tim Monks Vision, Speech and Signal Processing
- tpm@ecs.soton.ac.uk Southampton University
- Tel: +44 (703) 592774 Fax: +44 (703) 592895
-