Results 1 to 2 of 2

Thread: How to inheriting a enum type?

  1. #1
    Join Date
    Jan 2013
    Posts
    17
    Thanks
    9

    Default How to inheriting a enum type?

    Anyone knows a alternative to inheriting a enum and add more constants inside derived class?
    Is it possible and it will work with switch and if?

    Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to inheriting a enum type?

    There is no way to directly inherit an enum in C++.
    But you can create a simple workaround:
    Qt Code:
    1. class MyEnumBase{
    2. public:
    3. enum{
    4. Symbol1,
    5. Symbol2
    6. };
    7. };
    8.  
    9. class MyEnumDerived : public MyEnumBase{
    10. public:
    11. enum{
    12. Symbol3 = Symbol2+1,
    13. Symbol4
    14. };
    15. };
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to stampede for this useful post:

    ricardodovalle (27th February 2014)

Similar Threads

  1. Replies: 2
    Last Post: 27th November 2013, 01:56
  2. Inheriting QAbstractItemView
    By morfis in forum Newbie
    Replies: 2
    Last Post: 6th February 2013, 11:49
  3. Inheriting
    By tuxit in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2011, 13:28
  4. Problem with connect() (enum-type as parameter)
    By alu23 in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 08:46
  5. Inheriting QListViewItem
    By ct in forum Newbie
    Replies: 1
    Last Post: 17th March 2006, 06:52

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.