Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. C++ stuff you _never_ use?

C++ stuff you _never_ use?

Scheduled Pinned Locked Moved The Lounge
c++comquestion
19 Posts 11 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Paul Westcott

    From the amount of confusion the terminology has caused here I think it's pretty obvious that most people don't use virtual base classes as they don't even know what they are =) [No, I have never used them, not even in a classroom setting] A couple of other people mentioned they don't use MI. I think MI mixed with templates is a fantastic way of implementing interfaces (ie. ATL), and the thing causes the most concern for me as I consider the c# future... Back to virtual base classes though - isn't that the corner stone of c++'s iostream? My memory says that was the (only!) example used whenever virtual base classes were mentioned??? Have fun, Paul Westcott.

    M Offline
    M Offline
    Michael Dunn
    wrote on last edited by
    #9

    Right you are, Paul. iostream uses VBCs: class istream : virtual public ios class ostream : virtual public ios class iostream : public istream, public ostream This is the case with the old-school classes from iostream.h. I never can make sense of the code in the new-style STL headers (like iostream) since the template and function parameters are given meaningless names. :( --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

    L 1 Reply Last reply
    0
    • M Michael Dunn

      I was just thinking about obscure C++ features. You know, stuff that you only use in classrooms. :) One really odd feature (in my mind, at least) is virtual base classes. I know the syntax, and I know what it does. But I've literally never seen them used in practice. Has anyone used them in a real project? I'm just curious how they're used in actual code (meaning, code not out of a textbook). --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

      E Offline
      E Offline
      Eddie Velasquez
      wrote on last edited by
      #10

      - Virtual base classes: Never used or needed - Covariant return types: Seldomly used or needed - Partial Template Specialization: Never used, seldomly needed - Multiple inheritance: Only used when modeling "interfaces" using Abstract Base Classes

      1 Reply Last reply
      0
      • M Michael Dunn

        I was just thinking about obscure C++ features. You know, stuff that you only use in classrooms. :) One really odd feature (in my mind, at least) is virtual base classes. I know the syntax, and I know what it does. But I've literally never seen them used in practice. Has anyone used them in a real project? I'm just curious how they're used in actual code (meaning, code not out of a textbook). --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

        S Offline
        S Offline
        Sardaukar
        wrote on last edited by
        #11

        1. Virtual base classes? Having a shell context extension to implement and two classes: CContextMenu (public IContextMenu) and CShellExtInit (public IShellExtInit), you'll probably have to write CShellExtension : public CCOntextMenu, public CShellExtInit... Or (this is really used in a large project): having a CDlgProtect (dialog catching exceptions) and CDlgResize (dialog that automates the resizing of controls inside), both derived from MFC's CDialog, the majority of the dialogs are derived from class CDlgProtectResize : public CDlgProtect, public CDlgResize { public: CDlgProtectResize(CWnd * _pWndParent, CModuleManager *_pModMan = NULL); virtual ~CDlgProtectResize(); public: virtual void OnException(); // from CDlgProtect virtual void OnResize(); // from CDlgResize } Am I reaching you?

        1 Reply Last reply
        0
        • P Paul Westcott

          From the amount of confusion the terminology has caused here I think it's pretty obvious that most people don't use virtual base classes as they don't even know what they are =) [No, I have never used them, not even in a classroom setting] A couple of other people mentioned they don't use MI. I think MI mixed with templates is a fantastic way of implementing interfaces (ie. ATL), and the thing causes the most concern for me as I consider the c# future... Back to virtual base classes though - isn't that the corner stone of c++'s iostream? My memory says that was the (only!) example used whenever virtual base classes were mentioned??? Have fun, Paul Westcott.

          L Offline
          L Offline
          Leo Davidson
          wrote on last edited by
          #12

          You're not wrong. :-) This page gives a good example of virtual base classes (how they are used and what they are good for): http://www.programmingjunkies.com/cppbook/Cbook8\_12.htm Am I right that covariant returns just allow a virtual function to be overridden by another function which takes the same arguments but returns a different type, so long as that type derives from (or is the same as) the original function's type? Are there any catches with this? (I found a comment about static typing but there wasn't much context for me to understand what they meant.) Assuming I understand them, covariant returns seem useful (essential) for copy functions.

          1 Reply Last reply
          0
          • L Leo Davidson

            Ah, yes, I think you're right. :-) Oops. I need to brush up on my C++ terminology (I've started reading Stroustrup again :-)). I also completely avoid multiple inheritance. When learning OO at university I was told it's dangerous concept and I tend to agree.

            C Offline
            C Offline
            Christian Skovdal Andersen
            wrote on last edited by
            #13

            You say that MI (Multiple Inheritance - nothing to do with Tom Cruise) is a dangerous concept - but isn't that the whole idea with C++? You get the freedom and all the 'dangerous' tools. It's your job avoiding shooting yourself in the foot. I think this is where C++ really sets itself apart from most common languages. Christian Skovdal Andersen

            1 Reply Last reply
            0
            • M Michael Dunn

              Right you are, Paul. iostream uses VBCs: class istream : virtual public ios class ostream : virtual public ios class iostream : public istream, public ostream This is the case with the old-school classes from iostream.h. I never can make sense of the code in the new-style STL headers (like iostream) since the template and function parameters are given meaningless names. :( --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #14

              Mention that on the moderated C++ newsgroup and people will tell you that you're an idiot...for some reason the people there seem to have lots and lots of time on their hands and don't understand that making things clear is very important for people who are in the trenches trying to create applications.

              1 Reply Last reply
              0
              • M Michael Dunn

                I was just thinking about obscure C++ features. You know, stuff that you only use in classrooms. :) One really odd feature (in my mind, at least) is virtual base classes. I know the syntax, and I know what it does. But I've literally never seen them used in practice. Has anyone used them in a real project? I'm just curious how they're used in actual code (meaning, code not out of a textbook). --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

                Brian C HartB Offline
                Brian C HartB Offline
                Brian C Hart
                wrote on last edited by
                #15

                Hey Mike, >...like virtual base classes; I've seen examples of them, but not really used in practice... What do you think COM interfaces are? :rolleyes: Even if you're not writing COM servers, but if you write a COM client and it calls CoCreateInstance() at least once, then you're also using virtual base classes. In addition, the MFC class CDocTemplate is a virtual base class... Plus, the STL uses function objects and template specifications all over the place. Get to know something really well before you bash it. STL's utility comes in handy when you're outside of MFC but you're wishing you had some high-performance list, map, or array (vector) functionality handy. Then again, every interface method is itself a virtual function, too... that's why your ATL class derives directly from the interface and then implements all its methods! Plus, ATL makes widespread use of multiple inheritance, and does it just fine, thank you very much. If you aren't using the 'obscure' parts of C++, then I would give a friendly suggestion to start increasing the variety of applications you develop... Brian Hart Brian

                Regards,

                Dr. Brian Hart
                drbrianhart343@gmail.com email
                LinkedIn: https://www.linkedin.com/in/dr-brian-hart-astrophysicist-veteran/

                A 1 Reply Last reply
                0
                • Brian C HartB Brian C Hart

                  Hey Mike, >...like virtual base classes; I've seen examples of them, but not really used in practice... What do you think COM interfaces are? :rolleyes: Even if you're not writing COM servers, but if you write a COM client and it calls CoCreateInstance() at least once, then you're also using virtual base classes. In addition, the MFC class CDocTemplate is a virtual base class... Plus, the STL uses function objects and template specifications all over the place. Get to know something really well before you bash it. STL's utility comes in handy when you're outside of MFC but you're wishing you had some high-performance list, map, or array (vector) functionality handy. Then again, every interface method is itself a virtual function, too... that's why your ATL class derives directly from the interface and then implements all its methods! Plus, ATL makes widespread use of multiple inheritance, and does it just fine, thank you very much. If you aren't using the 'obscure' parts of C++, then I would give a friendly suggestion to start increasing the variety of applications you develop... Brian Hart Brian

                  A Offline
                  A Offline
                  Andy Hassall
                  wrote on last edited by
                  #16

                  CDocTemplate's an abstract base class (a class with one or more pure virtual member functions), not a virtual base class. I don't know a lot about COM, but I doubt it's got much to do with virtual base classes either. Have you made the same mistake as Leo Davidson above? I agree about STL being extremely useful, and I wouldn't call it obscure at all :-)

                  1 Reply Last reply
                  0
                  • M Michael Dunn

                    I was just thinking about obscure C++ features. You know, stuff that you only use in classrooms. :) One really odd feature (in my mind, at least) is virtual base classes. I know the syntax, and I know what it does. But I've literally never seen them used in practice. Has anyone used them in a real project? I'm just curious how they're used in actual code (meaning, code not out of a textbook). --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #17

                    I don't think there is a feature of C++ that I haven't used at some point, including virtual base classes. People say C++ is far too complicated, but every single feature is there for a very good reason, and taking it out really wouldn't make it the general purpose programming language it is. E.g., virtual inheritance is pretty important in a lot of big class hierarchies -- e.g., the iostream hierarchy in the C++ library. If you've never used a feature of C++, and wondering where it gets used, I recommend Stroustrup's 2nd book, called something along the lines of "The Design & Evolution of C++". it explains his reasoning behind every feature.

                    1 Reply Last reply
                    0
                    • M Michael Dunn

                      I was just thinking about obscure C++ features. You know, stuff that you only use in classrooms. :) One really odd feature (in my mind, at least) is virtual base classes. I know the syntax, and I know what it does. But I've literally never seen them used in practice. Has anyone used them in a real project? I'm just curious how they're used in actual code (meaning, code not out of a textbook). --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

                      M Offline
                      M Offline
                      Mike Melnikov
                      wrote on last edited by
                      #18

                      Hi I am using virtual base classes a lot. This is simple example: class AUnknown // this is base "interface" class { Object* m_owner; // pointer to base "object" class }; class IMove : virtual public AUnknown { void move() = 0; }; class IName : virtual public AUnknown { string getName() = 0; void setName(string) = 0; }; // class that implements two interfaces and has only one //instance of m_owner; class CanMoveHasName : public IMove, public IName { }; Mike

                      1 Reply Last reply
                      0
                      • M Michael Dunn

                        I was just thinking about obscure C++ features. You know, stuff that you only use in classrooms. :) One really odd feature (in my mind, at least) is virtual base classes. I know the syntax, and I know what it does. But I've literally never seen them used in practice. Has anyone used them in a real project? I'm just curious how they're used in actual code (meaning, code not out of a textbook). --Mike-- http://home.inreach.com/mdunn/ "That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas." -- Buffy

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #19

                        I've never had a rason to use a union.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups