Constructor help (simple).

Hello,

I am writing a beam analysis program, and I need to use a constructor method defining the + sign as increasing the length L of the beam by the amount passed as the parameter to the method.
For instance, if the object variable is named THE_BEAM, then the statement THE_BEAM + 5; should add 5 inches to the length L of the beam object and recalculate all of the calculated values.

I am having some trouble figuring out how to do this...can anyone give me some pointers? I have included sections of my code below:

BEAM operator + (BEAM);

BEAM BEAM::operator + (BEAM beamlength)
{
double newL;
BEAM newlength;
newL=L+beamlength.L;
newlength.L=newL;
return newlength;}


main program:
//parameter for original length (also a user-input):
double Ll;

if (menu == 5)
{
BEAM P1,P2;
double input;
cout << "Please enter the length of the section to weld: " << endl;
cin >> input;
P1.L=input;
cout << "The length to weld is: " << P1.L;
P2=P1 + Ll;
cout << P2;
}

you can do like

return BEAM(L+beamlength.L)

But you will have to add a new constructor that takes beamlength as an argument
closed account (zb0S216C)
Duplicate: http://www.cplusplus.com/forum/beginner/69577/

Wazzak
Topic archived. No new replies allowed.