Solved

Overloading the < operator

Posted on 2000-04-28
3
162 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
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

786 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