Re: Virtual functrions and inheritance--hard to phrase question

From: Squeamizh (adsf_at_adf.adsf)
Date: 06/08/04


Date: Tue, 08 Jun 2004 05:42:58 GMT

On Tue, 08 Jun 2004 03:01:23 GMT, "Victor Bazarov"
<v.Abazarov@comAcast.net> wrote:

>"Squeamizh" <adsf@adf.adsf> wrote...
>> I'm having an issue where my compiler is not letting me do something
>> that I think I should be able to do. I'm finding it very difficult to
>> express my problem with a description, so I'm just going to give an
>> example of something similar to what I'm doing...I hope it's
>> understandable. Here's the situation:
>>
>> class Alpha {
>> public:
>> virtual void translate(void) = 0;
>> ...
>> };
>>
>> class Beta : public Alpha {
>> public:
>> void translate(void);
>> ...
>> };
>>
>>
>> class TranslatableInterface {
>> public:
>> virtual void translate(void) = 0;
>> };
>>
>> class Gamma : public Beta, public TranslatableInterface {
>> ... //translate is not overridden here.
>> };
>>
>>
>>
>> But if I try to instantiate a Gamma object it tells me that Gamma is
>> an abstract class due its reference to the undefined virtual
>> translate function. Do I really have to create another translate
>> function within Gamma that just calls Beta::translate() ? God I hope
>> not, that would be annoying.
>
>You will have to. There are two base classes in Gamma, and one of
>them is abstract. That makes Gamma abstract until you define the
>final overrider for 'TranslatableInterface::translate'.
>
>What I fail to understand, really, is why you inherited Beta from
>Alpha and not from TranslatableInterface. If you did, you'd have
>no problem whatsoever:
>
> struct TranslatableInterface {
> virtual void translate() = 0;
> };
>
> struct Beta : virtual TranslatableInterface {
> void translate() {}
> };
>
> struct Gamma : Beta, virtual TranslatableInterface { };
>
> int main()
> {
> G g;
> A &a = g;
> a.translate();
> }
>
>Victor

Thanks.

I intentionally made the example simple, but now that I look at it I
can see why it seems like an irrational thing to do. Basically, Alpha
can do more than translate, and TranslateableInterface also has more
functionality than just to translate (It's definitely not called
'TranslatableInterface'), but I need the ability to translate Gamma
via either type of reference. I incorrectly assumed that, since Gamma
does inherit a translate function somewhere down the line, that that
should take care of any virtual void translate()s that it has.



Relevant Pages

  • RUN process /ON=node
    ... BIKE is an ALPHA, ... translated on VAXes and points to an ALPHA root when on an ALPHA. ... the fileID of the VAX executable because the "APPL" would be translated ... and then translate APPL itself. ...
    (comp.os.vms)
  • Re: Write a string in EBCDIC
    ... >> Write a translate function and voila, ... Write a separate setup_xlate_table function for each EBCDIC you are ... For instance, how do you translate ... > character) to EBCDIC-US? ...
    (comp.lang.c)
  • Re: put away characters in result of query
    ... > "translate" only translate known characters with known characters, ... characters in the the 2nd parameter of the translate function that do not ... the first translate just shows how it works ...
    (comp.databases.oracle.misc)
  • Re: put away characters in result of query
    ... "translate" only translate known characters with known characters, ... null string) ... > Take a look at TRANSLATE function. ...
    (comp.databases.oracle.misc)