Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

error e2093: how to avoid it?

Posted on 2001-06-09
5
Medium Priority
?
366 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:ef239
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 6171795
The problem is that your classes are not const correct (contant correct).

in code like

a+(b+c)

the b+c is performed first and this creates an unnamed temporary object, then this unamed temporary object is added to a.  As if you did

cls_vector temp = b+c;
a + temp;

the problem is that unnamed temporaries nmust be treated like constant objects.  but your functions are declared to take non-constant parameters.  This makes sense.  Why woudl you want to change a temproary value that you never "see".  If the functions really do alter their parameters, then you must leave them this way and you may not use the function as you trying to do so.  But that is unlikely.  so most likely you shoiuld follow the standard convention passing constant parmaters do the binary mathematical operators.


0
 
LVL 22

Expert Comment

by:nietod
ID: 6171799
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);
}
0
 
LVL 22

Expert Comment

by:nietod
ID: 6171801
>>  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.
0
 
LVL 22

Expert Comment

by:nietod
ID: 6171824
>> //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.
0
 

Author Comment

by:ef239
ID: 6173488
ok, thanks for your help!
(i compiled it with borland free command line tools 5.5)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question