Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > comparison operators parameter

Reply
Thread Tools

comparison operators parameter

 
 
Philipp Kraus
Guest
Posts: n/a
 
      05-21-2011
Hello,

I' writing a class with a method, that should get a parameter for
comparision like <, <=, > or >=. The method must compare some float
values but the user of the method should be set the comparision. My
first idea is to use an enum with 4 states of comparision, but is there
a better solution?

In pseudocode:

myclass::mymethod( comparision_operator p_comp ) {
float a,b;
if ( p_comp(a,b))
do something
}

Thx

Phil

 
Reply With Quote
 
 
 
 
Öö Tiib
Guest
Posts: n/a
 
      05-21-2011
On May 21, 8:58*pm, Philipp Kraus <philipp.kr...@flashpixx.de> wrote:
> Hello,
>
> I' writing a class with a method, that should get a parameter for
> comparision like <, <=, > or >=. The method must compare some float
> values but the user of the method should be set the comparision. My
> first idea is to use an enum with 4 states of comparision, but is there
> a better solution?
>
> In pseudocode:
>
> myclass::mymethod( comparision_operator p_comp ) {
> * * float a,b;
> * * if ( p_comp(a,b))
> * * * *do something
>
> }


Usually function objects are used there in C++. Objects of class that
overloads 'bool operator()(float,float) const'.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparison operators Joe Van Dyk C++ 4 08-10-2006 08:00 PM
synthesis of comparison operators sybhs@yahoo.com VHDL 1 05-15-2006 04:58 PM
How the comparison operators are defined for iterator and const_iterator PengYu.UT@gmail.com C++ 2 10-23-2005 04:33 PM
Comparison Operators J Jones ASP .Net 1 12-24-2003 01:17 AM
friend vs member for comparison operators Michael Klatt C++ 4 10-21-2003 02:18 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57