Homework: Function Templates

  < Previous  Next >

For this homework assignment, submit a copy of hwkFunctionTemplates.cpp that has:
  1. A templated add() function that takes two arguments, each of which can be a separate type, and returns the result of calling the + operator on the arguments. The return type should be the type of the first argument.
  2. A call to add(), passing it answer and pi
  3. A call to add(), passing it str1 and str2
No other changes should be necessary.

Your copy needs to compile on ranger using the following command-line:
g++  -std=c++0x  hwkFunctionTemplates.cpp
Finally, when your code is executed, the output must match what's in hwkFunctionTemplates-stdout.txt exactly:
45
Yeah, my templated function works!

Rubric:

Points         Item
---------      --------------------------------------------------------------
_____ / 3      1	       
_____ / 1      2	       
_____ / 1      3	       
        
_____ / 5      Total
      

Notes

  1. You should verify that your output matches the above output exactly with the following commands on ranger:
    g++  -std=c++0x  hwkFunctionTemplates.cpp  -o hwkFunctionTemplates-yourlastname
    ./hwkFunctionTemplates-yourlastname  &>  hwkFunctionTemplates-yourlastname.txt
    diff  /nfshome/hcarroll/public_html/3110/private/hwk/hwkFunctionTemplates-stdout.txt  hwkFunctionTemplates-yourlastname.txt
    

Last Modified: