Solved

Overloading the < operator

Posted on 2000-04-28
3
165 Views
Last Modified: 2010-04-02
I get some weird error message saying:

E:\vc++\Private\StarDist\CFlexPoint.h(53) : error C2662: 'Y' : cannot convert 'this' pointer from 'const class CFlexPoint' to 'class CFlexPoint &'

when I try to overload the < operator..

WHAT IS WRONG???
THIS IS KILLING ME!!!
0
Comment
Question by:lar_jens
[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
3 Comments
 
LVL 5

Expert Comment

by:proskig
ID: 2760486
Please post your code for this operator and its definition
0
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 2760594
it sounds like you declated operator < to be a const function, which it usually is, by including a "const" after the function's parameters, like the final "const" in

bool SomeClass::operator <(const SomeClass &Rht) const;

That is fine, in fact usually prefereable, but it means that the object that the function is invoked for must be treated as a constant object.  If you try to change the object, or try to call a non-constant member function (one that doesn't hae this "const" at the end), then you will get this error.

How to go about fixing the problem depends on details you haven't provided.
0
 
LVL 1

Author Comment

by:lar_jens
ID: 2761908
Thank you..
I solved my problem, and got wiser..

Couldn't get better...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

737 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