The files for this lab are in ~cs253/pub/Labs/AlphaOpLab.
As you know, C++ operators can be overloaded. However, you can’t create any new operators. You can’t create a statement like this:
x = y $ z;
because there is no operator $
. There just isn’t, and you can’t create it.
However, one can create new operators, well, sort of.
Consider the file infix.cc.
Compile it (avoid -Wall
) and execute it.
Look at main()
. It uses <MAX>
and <zap>
as if they were
operators, like +
or -
. Clearly, this is impossible, yet it works.
Look at class MyMax
and class Purge
. These are functor classes.
What do their functions do?
Now, look at these lines:
AlphaOp<MyMax> MAX; AlphaOp<Purge> zap;
The first declares an object called MAX
, of type AlphaOp<MyMax>
.
Now, consider AlphaOp.h. Figure it out.
<foo>
,
and make it work.
Modified: 2013-04-25T16:39 User: Guest Check: HTML CSSEdit History Source |
Apply to CSU |
Contact CSU |
Disclaimer |
Equal Opportunity Colorado State University, Fort Collins, CO 80523 USA © 2015 Colorado State University |