C++ Operators
-
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
-
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
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 -
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-2002Well, 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!
-
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
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 -
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 LucsyUhm. 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.
-
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ö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
-
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!
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