Link to home
Start Free TrialLog in
Avatar of ef239
ef239

asked on

error e2093: how to avoid it?

hello,
i hope some of you are c++ gurus and can help me:

long time ago i've written my own vector class:

class cls_vector
{
     ...
     cls_vector mth_sum(cls_vector &rfr_vector_2);
     cls_vector operator+(cls_vector &rfr_vector_2);
     ...
};

(both methods do exactly the same)

now i wanted to compile a simple test program with the borland c++ compiler (bcc32):

//works fine!
a.mth_sum(b+a); //a and b are both vector objects

//causes e2093
a+(b+a);

and now i get the following error message:
"e2093 operator '+' not implemented in type 'cls_vector' for arguments of the same type"!

i really don't know what the reason for this error is because i compiled these expressions with turbo c++ without any errors!
and i don't see any difference between these expressions but it still doesn't work!

please help me!
thanks, 239
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

for example,

cls_vector mth_sum(const cls_vector &rfr_vector_2) const
cls_vector operator+(const cls_vector &rfr_vector_2) const;
                 ...
this decalres both the named parameter and the "this" parameter as constants.

Note however, that it is usually a bette idea to declare operator + as a free function, not as a member function.  Among other reasons this will allow automatic conversions to be applied to both the left and right operands.  if the operator is a meber function, then the conversios will be aplied to only the right operand.  fior example

cls_vector operator+(const cls_vector &rfr_vector_1,const cls_vector &rfr_vector_2)
{
   return vactor_1.mth_sum(vector_2);
}
>>  i compiled these expressions with turbo
>> c++ without any errors!
turbo C++ was abandoned 7+ years before the C+ standard was completed.  Its about as current as gas lamps and horse-drawn carriages.
>> //works fine!
>> a.mth_sum(b+a); //a and b are both vector objects
Technically this should not compile either.  If it does, your compiler is at fault.  If you are using an outdated compiler like one of the free copies of BCB you might find that code like this still compiles, evne though it shouldn't.  Your best bet is to modernize.
Avatar of ef239

ASKER

ok, thanks for your help!
(i compiled it with borland free command line tools 5.5)