Click here to Skip to main content
15,898,947 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to get a status from ITask Pin
StefanKittel3-Sep-07 10:40
StefanKittel3-Sep-07 10:40 
AnswerRe: How to get a status from ITask Pin
Hamid_RT3-Sep-07 18:52
Hamid_RT3-Sep-07 18:52 
QuestionHow to launch exe file with command line? Pin
jerome_data3-Sep-07 7:38
jerome_data3-Sep-07 7:38 
AnswerRe: How to launch exe file with command line? Pin
Mark Salsbery3-Sep-07 8:26
Mark Salsbery3-Sep-07 8:26 
AnswerRe: How to launch exe file with command line? Pin
Hamid_RT3-Sep-07 18:50
Hamid_RT3-Sep-07 18:50 
AnswerRe: How to launch exe file with command line? Pin
Jason Teagle3-Sep-07 22:37
Jason Teagle3-Sep-07 22:37 
Question860612 - automatic expand in outlining Pin
ilostmyid23-Sep-07 6:01
professionalilostmyid23-Sep-07 6:01 
QuestionProblem defining operator<(rhs) Pin
John R. Shaw3-Sep-07 5:50
John R. Shaw3-Sep-07 5:50 
When determining if the value stored in an object is less than that stored in another object we define the operator ‘<’; how it is defined is very important. But how do you define the operator for a class with multiple data items, so that you get the correct results?

For reasons that I am not going to go into, we do not care what data is stored or what its actual value is. We simply need to be able to determine whether one object is less than another for the purpose of adding it to an STL container that requires the information.

One solution is to just do a simple ‘memcmp()’ , which does work under normal usage of this particular class. The reason it works is because the ‘data_type’ is normally an integral type.

The problem is that the data type is unknown, as the class is a template and the type is supplied by the user. If the data type is a class that contains no memory pointers, the above solution will still work. But if the data type is a class that contains a memory pointer, such as a ‘std::string’, then the above solution is invalid because comparing data pointers is not the same as comparing the data pointed to.

For the purposes of comparison, every piece of data (data_, f1_,…, and id_) must be used. The ‘memcmp()’ method produces the correct results for integral types, but every other method I have tried fails. The results of the comparison must be the same as that produced by the ‘memcmp()’ method.

Note that “(data_ < rhs.data_ || f1_ < rhs.f1_ || f2_ < rhs.f2_ || f3_ < rhs.f3_ || id _ < rhs.id _)” does not work, nor other variations on that theme.

Example class:
class this_class
{
    data_type data_; // unknown data type
    bool f1_, f2_, f3_;
    int id_;
public:
    
    // Operators
    bool operator<(const this_class& rhs) const
    { return( memcmp(this,&rhs,sizeof(class)) < 0 ); }
};



INTP
"Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

AnswerRe: Problem defining operator&lt;(rhs) Pin
Russell'3-Sep-07 7:05
Russell'3-Sep-07 7:05 
AnswerRe: Problem defining operator&amp;lt;(rhs) Pin
Stephen Hewitt3-Sep-07 14:58
Stephen Hewitt3-Sep-07 14:58 
GeneralRe: Problem defining operator&amp;lt;(rhs) Pin
John R. Shaw3-Sep-07 18:26
John R. Shaw3-Sep-07 18:26 
GeneralRe: Problem defining operator&amp;amp;lt;(rhs) Pin
Stephen Hewitt3-Sep-07 18:54
Stephen Hewitt3-Sep-07 18:54 
GeneralRe: Problem defining operator&amp;amp;lt;(rhs) Pin
John R. Shaw5-Sep-07 16:03
John R. Shaw5-Sep-07 16:03 
GeneralRe: Problem defining operator&amp;amp;lt;(rhs) Pin
Stephen Hewitt5-Sep-07 16:15
Stephen Hewitt5-Sep-07 16:15 
Questionany good 3ds max plugin guide? Pin
nathan73-Sep-07 5:10
nathan73-Sep-07 5:10 
AnswerRe: any good 3ds max plugin guide? Pin
Hamid_RT3-Sep-07 6:36
Hamid_RT3-Sep-07 6:36 
Questionwhether GA can perform character recognition task? Pin
rayluee3-Sep-07 5:08
rayluee3-Sep-07 5:08 
QuestionIMPLEMENT_DYNCREATE with parameters using RTTI or other methods - seeking comments Pin
Vaclav_3-Sep-07 5:07
Vaclav_3-Sep-07 5:07 
QuestionSelect a combo box Pin
Fernando A. Gomez F.3-Sep-07 4:52
Fernando A. Gomez F.3-Sep-07 4:52 
AnswerRe: Select a combo box Pin
Nishad S3-Sep-07 4:54
Nishad S3-Sep-07 4:54 
GeneralRe: Select a combo box Pin
Fernando A. Gomez F.3-Sep-07 4:57
Fernando A. Gomez F.3-Sep-07 4:57 
GeneralRe: Select a combo box Pin
Nishad S3-Sep-07 5:00
Nishad S3-Sep-07 5:00 
GeneralRe: Select a combo box Pin
Fernando A. Gomez F.3-Sep-07 5:06
Fernando A. Gomez F.3-Sep-07 5:06 
AnswerRe: Select a combo box Pin
Stephen Hewitt3-Sep-07 15:05
Stephen Hewitt3-Sep-07 15:05 
GeneralRe: Select a combo box Pin
Fernando A. Gomez F.3-Sep-07 16:05
Fernando A. Gomez F.3-Sep-07 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.