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. Other Discussions
  3. Clever Code
  4. C# rots your C++ brain part 2

C# rots your C++ brain part 2

Scheduled Pinned Locked Moved Clever Code
csharpc++question
22 Posts 15 Posters 86 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.
  • J James_Zhang

    no idea. c# rotted my c++ brain too. not that i was really good at c++ though. i think that you can't do this in c++, but you can in c#?

    J Offline
    J Offline
    Jorgen Sigvardsson
    wrote on last edited by
    #10

    No, you can't make this mistake in C#, because you cannot specify whether the inheritance should be private or not. Inheritance is always public in C#.

    1 Reply Last reply
    0
    • C Chris Maunder

      :sigh: I think I need to take 2 weeks off and go back to straight C++.

      cheers, Chris Maunder

      CodeProject.com : C++ MVP

      J Offline
      J Offline
      Jorgen Sigvardsson
      wrote on last edited by
      #11

      If parsing C++ wasn't so damn hard, I'd write a tool to find these things for me. During the build process at 2 am, the build server would send me an SMS for each find. Do you know if Lint can find these kinds of things? :~

      L 1 Reply Last reply
      0
      • J Jorgen Sigvardsson

        If parsing C++ wasn't so damn hard, I'd write a tool to find these things for me. During the build process at 2 am, the build server would send me an SMS for each find. Do you know if Lint can find these kinds of things? :~

        L Offline
        L Offline
        led mike
        wrote on last edited by
        #12

        C# rots your C++ brain

        C# rots your C++ brain

        imagine what it does to non c++ brains (example: "The other day I saw the tooth fairy sodomizing easter bunny using a Dispose Pattern, SIDEWAYS!" :omg: ) ;)

        led mike

        S 1 Reply Last reply
        0
        • J Jorgen Sigvardsson

          class MyException : std::exception {
          ...
          }

          try {
          throw MyException();
          } catch(std::exception& ex) {
          }

          The exception is not going to be caught. Can you figure out why?

          A Offline
          A Offline
          Anthony Mushrow
          wrote on last edited by
          #13

          C# hasn't rotted my brain, I saw that straight away. Maybe it's just you. :confused:

          My current favourite word is: Nipple!

          -SK Genius

          Game Programming articles start -here[^]-

          1 Reply Last reply
          0
          • L led mike

            C# rots your C++ brain

            C# rots your C++ brain

            imagine what it does to non c++ brains (example: "The other day I saw the tooth fairy sodomizing easter bunny using a Dispose Pattern, SIDEWAYS!" :omg: ) ;)

            led mike

            S Offline
            S Offline
            Shog9 0
            wrote on last edited by
            #14

            Yes. You definitely need less C#. :)

            ----

            You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

            L 1 Reply Last reply
            0
            • S Shog9 0

              Yes. You definitely need less C#. :)

              ----

              You're right. These facts that you've laid out totally contradict the wild ramblings that I pulled off the back of cornflakes packets.

              L Offline
              L Offline
              led mike
              wrote on last edited by
              #15

              Shog9 wrote:

              You definitely need less C#

              I'm trying. I have started working with our C code base last year. It's a nightmare of course, unstructured, retarded spaghetti code. Unfortunately I still double duty in the wonderful new .NET world of our shop as well. I can't help but laughcry whenever I think about the dispose pattern. Here, we give you ( developers that can't deal with memory management "pointers" ) this magical world of garbage collection to eliminate the burden of understanding how computers work. This new magical world provides more native access than Java and so make sure to take a look at the, *gulp* simple eh yeah eh simple Dispose Pattern to ensure you are allocating and releasing native resources correctly. LMAO! Sure, they can't deal with pointers but they'll get this Dispose Pattern no problem! ROTF! :laugh::laugh::laugh:

              led mike

              1 Reply Last reply
              0
              • J Jorgen Sigvardsson

                That's the trick. In hindsight, the compiler is absolutely right. I would like C++ compiler writers to issue a warning whenever private inheritance is used and the class itself is used for exceptions.

                -- Kein Mitleid Für Die Mehrheit

                L Offline
                L Offline
                Le centriste
                wrote on last edited by
                #16

                Frankly, I don't see the point of private inheritance. I see it more like a <<uses>> than an <<is>>.

                J S 2 Replies Last reply
                0
                • L Le centriste

                  Frankly, I don't see the point of private inheritance. I see it more like a <<uses>> than an <<is>>.

                  J Offline
                  J Offline
                  Jorgen Sigvardsson
                  wrote on last edited by
                  #17

                  That is exactly the purpose it is intended to serve. It's there to save some extra typing for programmers. Instead of aggregating another object as a member variable, it's merged together with the "this" object. I think the language should've required the use of a visibility modifier. That way it wouldn't have been such a potential source of errors.

                  1 Reply Last reply
                  0
                  • N Nougat H

                    This works:

                    class MyException : public std::exception {

                    I had to write it down to see it. :D

                    K Offline
                    K Offline
                    Kevin McFarlane
                    wrote on last edited by
                    #18

                    Ah yes, I didn't spot that! It's the kind of nasty trick they would pull on you at interview. :) I haven't done any C++ for about 4 years now.

                    Kevin

                    1 Reply Last reply
                    0
                    • J Jorgen Sigvardsson

                      class MyException : std::exception {
                      ...
                      }

                      try {
                      throw MyException();
                      } catch(std::exception& ex) {
                      }

                      The exception is not going to be caught. Can you figure out why?

                      E Offline
                      E Offline
                      edu net
                      wrote on last edited by
                      #19

                      it's not functionally useful to adorn c++ inheritance with the

                      private

                      modifier (or no modifier at all). just keep all inheritance

                      public

                      (and don't forget it). i couldn't spot the error as it would never have happened to me coz of the above rule.


                      Love is the illusion that one kiss is different from another. - e.m

                      1 Reply Last reply
                      0
                      • L Le centriste

                        Frankly, I don't see the point of private inheritance. I see it more like a <<uses>> than an <<is>>.

                        S Offline
                        S Offline
                        Steve_
                        wrote on last edited by
                        #20

                        But if it <<is>> it can access protected members.

                        1 Reply Last reply
                        0
                        • J Jorgen Sigvardsson

                          class MyException : std::exception {
                          ...
                          }

                          try {
                          throw MyException();
                          } catch(std::exception& ex) {
                          }

                          The exception is not going to be caught. Can you figure out why?

                          A Offline
                          A Offline
                          Al Beback
                          wrote on last edited by
                          #21

                          I admit I didn't spot the missing public modifier, but I noticed something else that I wasn't sure of: throw MyException**()**; In C++, you don't use parenthesis when instanciating an object with the default constructor (ie, throw MyException;). I'm trying to remember if using parenthesis in this case would trigger an unintended call to the copy constructor. Do you know?

                          ShamWow

                          J 1 Reply Last reply
                          0
                          • A Al Beback

                            I admit I didn't spot the missing public modifier, but I noticed something else that I wasn't sure of: throw MyException**()**; In C++, you don't use parenthesis when instanciating an object with the default constructor (ie, throw MyException;). I'm trying to remember if using parenthesis in this case would trigger an unintended call to the copy constructor. Do you know?

                            ShamWow

                            J Offline
                            J Offline
                            Jorgen Sigvardsson
                            wrote on last edited by
                            #22

                            It does not matter if you use the parenthesis or not, the default constructor is called anyway. I tend to use parenthesis (how the hell do you pluralize that word? :)), because it makes the syntax more uniform. There are some odd scenarios though, where the parenthesis can fool the compiler into believing that you're declaring a function prototype. Can't remember exactly how to provoke it though...

                            -- Kein Mitleid Für Die Mehrheit

                            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