overloaded name + inheritance

Discussion in 'C++' started by jrraines, Mar 20, 2010.

  1. jrraines

    jrraines Guest

    There is an arduino library for LCD displays called LiquidCrystal. At
    present the class has the ability to handle either 4 or 8 data pins
    and various forms of testing the LCD's busy flag. The initial part of
    the declaration looks like this:
    class LiquidCrystal : public Print {
    public:
    LiquidCrystal(uint8_t rs, uint8_t enable,
    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
    uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);

    LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
    uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);


    LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

    LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); //4x40 LCD w
    2x HD44780 controller chips, 2 enable lines to select between them 4
    data pins

    LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, void (*userFunc)
    (int8_t chip) ); //4x40 LCD w 2x HD44780 controller chips, 2 enable
    lines to select between them 4 data pins

    LiquidCrystal(uint8_t rs, uint8_t enable,
    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);

    LiquidCrystal(uint8_t rs, uint8_t enable,
    uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3 , void (*userFunc)
    (int8_t chip));

    The overloaded versions here imply that either 4 or 8 data pins will
    be used and all but one implies the specific form of the busy flag
    test. Presently each user gets object code that includes both 4 and 8
    bit capability and all versions of the busy test. It strikes me that I
    could refactor this with a protoclass that would include the common
    elements, then create new protoclasses that would handle either 4 or 8
    bits and finally create 7 classes that included just the appropriate
    busy test and code for 4 or 8 pins. I think each user would save
    several hundred bytes by eliminating the unnecessary portions of code.
    Some flags and flag testing would also vanish. On a little 8 bit
    Arduino, that is a significant benefit. The piece that I'm struggling
    with is whether it is possible to do this without changing the
    apparent API--can I have 7 versions that have the same overloaded name
    and have each of them inherit differently?
    jrraines, Mar 20, 2010
    #1
    1. Advertising

  2. On Sunday, March 21, 2010 03:58 AM, jrraines wrote:
    > There is an arduino library for LCD displays called LiquidCrystal. At
    > present the class has the ability to handle either 4 or 8 data pins
    > and various forms of testing the LCD's busy flag. The initial part of
    > the declaration looks like this:
    > class LiquidCrystal : public Print {
    > public:
    > LiquidCrystal(uint8_t rs, uint8_t enable,
    > uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
    > uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
    >
    > LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
    > uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3,
    > uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7);
    >
    >
    > LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable,
    > uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
    >
    > LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
    > uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3); //4x40 LCD w
    > 2x HD44780 controller chips, 2 enable lines to select between them 4
    > data pins
    >
    > LiquidCrystal(uint8_t rs, uint8_t rw, uint8_t enable, uint8_t en2,
    > uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, void (*userFunc)
    > (int8_t chip) ); //4x40 LCD w 2x HD44780 controller chips, 2 enable
    > lines to select between them 4 data pins
    >
    > LiquidCrystal(uint8_t rs, uint8_t enable,
    > uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3);
    >
    > LiquidCrystal(uint8_t rs, uint8_t enable,
    > uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3 , void (*userFunc)
    > (int8_t chip));
    >
    > The overloaded versions here imply that either 4 or 8 data pins will
    > be used and all but one implies the specific form of the busy flag
    > test. Presently each user gets object code that includes both 4 and 8
    > bit capability and all versions of the busy test. It strikes me that I
    > could refactor this with a protoclass that would include the common
    > elements, then create new protoclasses that would handle either 4 or 8
    > bits and finally create 7 classes that included just the appropriate
    > busy test and code for 4 or 8 pins. I think each user would save
    > several hundred bytes by eliminating the unnecessary portions of code.
    > Some flags and flag testing would also vanish. On a little 8 bit
    > Arduino, that is a significant benefit. The piece that I'm struggling
    > with is whether it is possible to do this without changing the
    > apparent API--can I have 7 versions that have the same overloaded name
    > and have each of them inherit differently?


    You are showing the constructors only. Constructors cannot be inherited.
    (although you can explicitly inherit them by a using declaration in C++0x)
    Michael Tsang, Mar 22, 2010
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DX
    Replies:
    3
    Views:
    394
  2. DX
    Replies:
    0
    Views:
    347
  3. Joe P
    Replies:
    1
    Views:
    296
    Pete Becker
    Jun 21, 2005
  4. Replies:
    8
    Views:
    355
  5. John Wickerbee

    Inheritance of overloaded ++ operator issue

    John Wickerbee, Oct 2, 2011, in forum: C Programming
    Replies:
    0
    Views:
    409
    John Wickerbee
    Oct 2, 2011
Loading...

Share This Page