CS253

This file defines the header for each page. An optional "icon" image (I use the textbook):

Replace this with info about this class:

CS253: Problem Solving with C++

Spring 2013

Alpha Op Lab

Links to the various pages for this class:

Wish I could do this: * Schedule

Alphabetic Operators Lab

Description

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.

infix.cc

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>.

AlphaOp.h

Now, consider AlphaOp.h. Figure it out.

Exercises

  1. Add a functor of your own design to infix.cc, bind it to <foo>, and make it work.

Modified: 2013-04-25T16:39

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building