function problem

I need to overload the operator+ and create a function template that adds two values and returns their sum.  What am I missing?

#include <iostream.h>
#include <fstream.h>
#include <conio.h>
#include <string.h>

template <class T>
T addroutine(T x, T y)
      T result;
      result = x + y;
            cout<< "Result = "<<result<<endl;

class homeWork
      char classname[15];
    int minutes;
    char assignment;

      homeWork(char num[], int min, char code);
      void showCall();
      homeWork operator+(Assign assign)

Assign assign:operator+(Assign assign)
      Assign newassign;
      strcpy(newassign, "Assigment Summary");
      newassign.classname = classname + newassign.classname;

void main()
      int x = 60, y = 10;

      cout<< "Result = "<<result<<endl;
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

template <class T>
T addroutine(T x, T y)
    T result;
    result = x + y;

    // cout<< "Result = "<<result<<endl;  this line never executes

void main()
    int x = 60, y = 10, result;
    result = addroutine<int>(x,y);

    cout<< "Result = "<<result<<endl;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Have you tried compiling it?
What type is Assign? To overload operator+ I would suggest something like:
homeWork& operator+ (const homeWork& toadd);
(1) You need to define your class Assign
(2) The cout in your addRoutine will not show because it is out of scope; you have the return before it.
(3) You are missing a semicolon after homeWork operator+(Assign assign)
(4) You are not assigning the value returned from addroutine(x,y) to a variable.
(5) cout in main is attempting to display an undeclared variable result
CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

rediceAuthor Commented:
Thanks for the comments. I will give them a try.

There are quite a few errors in your code.

First of all there is no class called 'Assign'. You have only one class 'homeWork'. So your function 'assign' (with a small 'a') should have declaration as:

homeWork operator+(homeWork assign)

In function definition it should be:

homeWork assign:operator+(homeWork assign)

Also your function is not correct. classname is an array of characters. It cannot be added directly as you have done.

It should be something like this:

homeWork assign:operator+(homeWork assign)
    homeWork newassign;
    strcpy(newassign.classname,classname);                       //Copy current classname to newassign.classname
    strcat(newassign.classname,assign.classname);           // Add the assign.classname at end of above classname

You will also have to create contructors for the class which will initialize values.

Also some sort of display function will be required to test the function you created.

Also in main you have to create two objects to test this function


homeWork a("First"),b("Second"),c;
c = a+b;

No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: AlexFM {http:#9825131}

Please leave any comments here within the next seven days.

EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.