Now the problem is that when i run the program, i get correct value of the two vectors, but i am not getting the right value for the addition...it might be the x_comp1 and so on are not getting those values even i am assigning them.....i am new to classes so pls help me out what is the actual problem...thanks
This would match your definition and implementation of a vector above (which isn't a proper vector - i'm assuming vector in terms of single dimensional matrix from you addition implementation).
hey SIK...it is working fine now...thanks....but what was the logic behind your code....and why my code was not working???? what is the problem in creating multiple instances of the same class????
hey awaise17, when you create multiple instances as in your initial main function you would then have a seperate piece of memory reserved for each instance of the vector class.
so in your case you would have an instance for object A, object B and object add.
Each of these objects will have their own set of member variables, ie x_comp1, x_comp2, ..., add_z
Therefor when you call A.v_input1(1, 2, 3), you are setting only object A's x_comp1, y_comp1 and z_comp1 values.
When you call B.v_input2(3, 4, 5), you are setting only object B's x_comp2, y_comp2 and z_comp2 values.
Also note that the member values (x_comp1, ... add_z) of each of these vector objects A, B, add will be undefined/garbage upon creation. You would need a contructor to have these initialized to something safe like zero at object creation.
Consequently the remaining values of your objects A and B that were not set is still garbage and so is your entire add object.
Therefor when you called the addition method on your add object it, applied the add operation to a bunch of garbage values (ie. it does not reference objects A and B at all, so setting the input 1 & 2 values in these objects was futile)