Jun 23, 2009 at 5:41pm UTC
code should display 90 and 225... I am having too many parameters error
#include <iostream>
using namespace std;
class TT
{
protected:
int value1;
int value2;
public:
TT(int i=0, int j=0) { value1 = i; value2 = j; }
/// need to do here for program to run
TT operator + (TT &other);
ostream& operator << (ostream & stream, TT &other);
}; // TT
//These are the functions:
TT TT::operator + (TT &other)
{
TT result;
result.value1 = value1 + other.value1;
result.value2 = value2 + other.value2;
return result;
}
ostream& TT::operator << (ostream & stream, TT &other)
{
return stream << "Value1 = " << other.value1 << ", Value2 = " << other.value2 <<endl;
}
int main() // You are NOT allowed to change the main() function.
{
TT Sum, A[3] = { TT(20, 50.0), TT(30, 75.0), TT(40, 100.0) };
for (int i=0; i < 3; ++i)
Sum = Sum + A[i];
cout << Sum;
return 0;
} // main
Last edited on Jun 24, 2009 at 8:02pm UTC
Jun 24, 2009 at 7:58pm UTC
I did whtever i could do...but now I am having "too many parameters" error.. HELP someone
Jun 24, 2009 at 8:11pm UTC
Move TT::operator<<() outside of TT (i.e. it should be a regular function, not a method).
Jun 24, 2009 at 8:59pm UTC
It probably should be declared as a friend function, and the "other" parameter should be a const reference.
Also, the "other" parameter on operator+ should be a const reference, and the method itself should be const (unless you also make it a friend).