Subj : Re: Need help, please! To : borland.public.cpp.borlandcpp From : "Ed Mulroy [TeamB]" Date : Tue Nov 25 2003 06:14 pm > ClassA operator-(const ClassA Obj1, const ClassA Obj2) That is a problem. Do not pass class instances by value. Pass them by reference or by const reference. For example: ClassA operator - (const ClassA& Obj1, const ClassA& Obj2) That's all I see at first glance. I'll look at it and get back to you. > I dont know how to return you the favour! There is a clear procedure for how you can pay for the help. When you see someone else burdened by a problem for which you know an answer, help him. You might even feel good about what you've done and he will have been helped - a situation where everybody wins. .. Ed > Bojidar Markov wrote in message > news:3fc3d0e3@newsgroups.borland.com... > > The whole task is: "Predefine the operator "-" using member function and > friend function." That's all. > > I tried to implement it using those two functions, but I cant with the > vectors. > If you help me get this working, I promise I will leave you! :) (I already > feel enough uncomfortable) > I just want a working example. Thats all. > > Heres the code snipped: > > //Global definition of the operator "-" which will be used later as friend > function of the class ClassA: > ClassA operator-(const ClassA Obj1, const ClassA Obj2) > { > ClassA tmp; > tmp.iMember = Obj1.iMember - Obj2.iMember; > return tmp; > } > > class ClassA > { > public: > int iMember; > > //Example for operator "-" as member function: > ClassA operator-( const ClassA Obj ) const > { > ClassA tmp; > tmp.iMember = iMember - Obj.iMember; > return tmp; > } > > //And as friend function of the class ClassA: > friend ClassA operator-(const ClassA Obj1, const ClassA Obj2); > } > > //Usage: > ClassA OBJ1, OBJ2; > OBJ1.iMember = 5; > OBJ2.iMember = 3; > > int iRes = OBJ1 - OBJ2; // iRes==2 > > I dont know how to return you the favour! .