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. General Programming
  3. C / C++ / MFC
  4. C++ Operators

C++ Operators

Scheduled Pinned Locked Moved C / C++ / MFC
c++
7 Posts 5 Posters 0 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.
  • N Offline
    N Offline
    Nilesh K
    wrote on last edited by
    #1

    Hi Is it possible to write our own operators ( I'm not talking about operator overloading ) in C++, like what the language itself offers. For e.g. currently the switch operator does not work with strings it needs constants so if I'm able to write a operator which would be similar to switch but be able to work strings also then it would be great. Ciao - Nilesh

    C J 2 Replies Last reply
    0
    • N Nilesh K

      Hi Is it possible to write our own operators ( I'm not talking about operator overloading ) in C++, like what the language itself offers. For e.g. currently the switch operator does not work with strings it needs constants so if I'm able to write a operator which would be similar to switch but be able to work strings also then it would be great. Ciao - Nilesh

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You cannot add keywords to the C++ language or change their behaviour excepting the mechanisms offered by operator overloading. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
      C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
      Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

      B 1 Reply Last reply
      0
      • C Christian Graus

        You cannot add keywords to the C++ language or change their behaviour excepting the mechanisms offered by operator overloading. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
        C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
        Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

        B Offline
        B Offline
        benjymous
        wrote on last edited by
        #3

        Well, you could probably do crafty stuff with defines, but that's not to be recommended at all (That reminds me of a bit of microsoft code I saw ages ago that used defines to make Pascal style for loops! arrgh!) -- Help me! I'm turning into a grapefruit!

        C 1 Reply Last reply
        0
        • N Nilesh K

          Hi Is it possible to write our own operators ( I'm not talking about operator overloading ) in C++, like what the language itself offers. For e.g. currently the switch operator does not work with strings it needs constants so if I'm able to write a operator which would be similar to switch but be able to work strings also then it would be great. Ciao - Nilesh

          J Offline
          J Offline
          Joel Lucsy
          wrote on last edited by
          #4

          I've been using a way to sorta do switch's on strings. The overall idea is to use a function that converts the string to a number. For convienence and speed I used CRC32. I also created a macro/add-in for DevStudio so that I can just highlight some text and calculate the CRC32. For instance: switch (Crc32( x )) { case 0xde080b5a/*lic*/: OnLicence(); break; case 0xb644dd13/*filestab*/: Tabs.ShowPage( 1 ); break; case 0xb4629e6c/*scripttab*/: Tabs.ShowPage( 2 ); break; } Personally I think it makes the code pretty readable and maintable (If you ignore how badly the html mangles the spacing). Sure it has to do a bit more work, but the code maintainence is a breeze. Joel Lucsy

          J 1 Reply Last reply
          0
          • J Joel Lucsy

            I've been using a way to sorta do switch's on strings. The overall idea is to use a function that converts the string to a number. For convienence and speed I used CRC32. I also created a macro/add-in for DevStudio so that I can just highlight some text and calculate the CRC32. For instance: switch (Crc32( x )) { case 0xde080b5a/*lic*/: OnLicence(); break; case 0xb644dd13/*filestab*/: Tabs.ShowPage( 1 ); break; case 0xb4629e6c/*scripttab*/: Tabs.ShowPage( 2 ); break; } Personally I think it makes the code pretty readable and maintable (If you ignore how badly the html mangles the spacing). Sure it has to do a bit more work, but the code maintainence is a breeze. Joel Lucsy

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

            Uhm. You call this maintainable? CRC checksums? :~ -- There's a new game we like to play you see. A game with added reality. You treat me like a dog, get me down on my knees. We call it master and servant.

            J 1 Reply Last reply
            0
            • J Jorgen Sigvardsson

              Uhm. You call this maintainable? CRC checksums? :~ -- There's a new game we like to play you see. A game with added reality. You treat me like a dog, get me down on my knees. We call it master and servant.

              J Offline
              J Offline
              Joel Lucsy
              wrote on last edited by
              #6

              Jörgen Sigvardsson wrote: Uhm. You call this maintainable? CRC checksums? With the proper tools, yes. All I have to do to update a string is highlight the checksum and corresponding string, including the comments, press a toolbar button and it's updated. Perhaps it's just me, but I dislike seeing a bunch of if statements. I'd rather see a switch. Note that I would not attempt this if I didn't have a add-in to regenerate the checksums. I even toyed with the idea of writing a small app that could be used in a pre-build custom step that would automatically refresh or generate any of the checksums. But I haven't run into any problems keeping up to date with the dozen of projects and numerous locations within each project. It just seems to work. If you have a better idea (and don't say a bunch of if's), then let me know. I realize it's not the most elegant, but it is quite efficient and, for me, quite readable. Joel Lucsy

              1 Reply Last reply
              0
              • B benjymous

                Well, you could probably do crafty stuff with defines, but that's not to be recommended at all (That reminds me of a bit of microsoft code I saw ages ago that used defines to make Pascal style for loops! arrgh!) -- Help me! I'm turning into a grapefruit!

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                Macros are almost *always* evil. Christian No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
                C# will attract all comers, where VB is for IT Journalists and managers - Michael P Butler 05-12-2002
                Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002

                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