![]() |
| | #1 |
| Registered User Join Date: Jun 2008 Location: NYC
Posts: 262
| Can someone explain this code? Code: for SpectrumColor operator++(SpectrumColor &s, int dummy)
{
return s = (s >= Violet) ? Red : SpectrumColor(s + 1);
}
|
| Sharke is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,353
| It looks like a typographical error: without the for, it would just be a non-member postfix operator++.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #3 | |
| The larch Join Date: May 2006
Posts: 3,222
| Also, it seems that it is operator++ for an enum: Code: #include <iostream>
enum SpectrumColor { Red, Orange, Yellow, Green, Blue, Indigo, Violet };
SpectrumColor operator++(SpectrumColor &s, int dummy)
{
return s = (s >= Violet) ? Red : SpectrumColor(s + 1);
}
int main()
{
SpectrumColor col = Blue;
col++;
std::cout << col << ' ';
col++;
std::cout << col << '\n';
col++;
std::cout << col << '\n';
}
__________________ I might be wrong. Quote:
| |
| anon is offline | |
| | #4 |
| Registered User Join Date: Jun 2008 Location: NYC
Posts: 262
| Aha, I'd hoped it was an error because it sure as hell didn't look like anything that made sense to me with that "for." Here I was worrying that I'd skipped a couple of chapters. Well, I guess I'll check the website for the errata. |
| Sharke is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Writing Code | ILoveVectors | C++ Programming | 4 | 06-13-2005 12:27 AM |
| True ASM vs. Fake ASM ???? | DavidP | A Brief History of Cprogramming.com | 7 | 04-02-2003 04:28 AM |
| Seems like correct code, but results are not right... | OmniMirror | C Programming | 4 | 02-13-2003 01:33 PM |
| Interface Question | smog890 | C Programming | 11 | 06-03-2002 05:06 PM |
| Can you have nested code block? What does the compiler do? For example ... | albertr | C Programming | 4 | 01-16-2002 12:04 AM |