Solved

Overloading the < operator

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 167
C++ question 3 74
C++ mouse_event mouse look 7 111
Are the two lines the same? If not what is the difference? 2 29
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…
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…
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 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…

740 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