Click here to Skip to main content
15,902,817 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Sorting a list with class for complex types Pin
Jun Du10-Jul-06 5:35
Jun Du10-Jul-06 5:35 
AnswerRe: Sorting a list with class for complex types [modified] Pin
FarPointer10-Jul-06 6:29
FarPointer10-Jul-06 6:29 
GeneralRe: Sorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 7:02
Harold_Wishes10-Jul-06 7:02 
GeneralRe: Sorting a list with class for complex types [modified] Pin
FarPointer10-Jul-06 7:28
FarPointer10-Jul-06 7:28 
QuestionRe: Sorting a list with class for complex types Pin
David Crow10-Jul-06 7:36
David Crow10-Jul-06 7:36 
AnswerRe: Sorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 7:48
Harold_Wishes10-Jul-06 7:48 
GeneralRe: Sorting a list with class for complex types [modified] Pin
FarPointer10-Jul-06 7:54
FarPointer10-Jul-06 7:54 
GeneralRe: Sorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 8:09
Harold_Wishes10-Jul-06 8:09 
I still could not get it to run. Confused | :confused:

C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(33) : error C2664: 'void __thiscall std::list<class mydata,class="" std::allocator<class="" mydata=""> >::sort(struct std::greater<class mydata="">)' : cannot convert parameter 1 from '
bool (const class MyData &,const class MyData &)' to 'struct std::greater<class mydata="">'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(36) : error C2955: 'list' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\list(415) : see declaration of 'list'
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(36) : error C2955: 'list' : use of class template requires template argument list
c:\program files\microsoft visual studio\vc98\include\list(415) : see declaration of 'list'
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(36) : error C2440: 'initializing' : cannot convert from 'class std::list<class mydata,class="" std::allocator<class="" mydata=""> >::iterator' to 'class std::list<_Ty,_A>::const_iter
ator'
No constructor could take the source type, or constructor overload resolution was ambiguous
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(36) : error C2262: 'citer' : cannot be destroyed
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(37) : error C2679: binary '!=' : no operator defined which takes a right-hand operand of type 'class std::list<class mydata,class="" std::allocator<class="" mydata=""> >::iterator' (
or there is no acceptable conversion)
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(39) : error C2228: left of '.m_iData' must have class/struct/union type
Error executing cl.exe.

Sort.exe - 7 error(s), 0 warning(s)

#include <list>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

class MyData
{
public:
  int m_iData;
  string m_strSomeOtherData;
};

bool MyDataSortPredicate(const MyData& lhs, const MyData& rhs)
{
  return lhs.m_iData < rhs.m_iData;
}

int main()
{
  // Create list
  list<MyData> mylist;

  // Add data to the list
  MyData data;
  data.m_iData = 3;
  mylist.push_back(data);
  data.m_iData = 1;
  mylist.push_back(data);

  // Sort the list using predicate
  mylist.sort(MyDataSortPredicate);

  // Dump the list to check the result
  for (list::const_iterator citer = mylist.begin();
     citer != mylist.end(); ++citer)
  {
    cout << (*citer).m_iData << endl;
  }

  return 0;
}


-- modified at 14:21 Monday 10th July, 2006
GeneralRe: Sorting a list with class for complex types Pin
FarPointer10-Jul-06 8:18
FarPointer10-Jul-06 8:18 
GeneralRe: Sorting a list with class for complex types Pin
Harold_Wishes10-Jul-06 8:33
Harold_Wishes10-Jul-06 8:33 
GeneralRe: Sorting a list with class for complex types Pin
David Crow10-Jul-06 9:11
David Crow10-Jul-06 9:11 
GeneralRe: Sorting a list with class for complex types Pin
Zac Howland10-Jul-06 8:39
Zac Howland10-Jul-06 8:39 
GeneralRe: Sorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 9:01
Harold_Wishes10-Jul-06 9:01 
GeneralRe: Sorting a list with class for complex types Pin
Zac Howland10-Jul-06 9:25
Zac Howland10-Jul-06 9:25 
GeneralRe: Sorting a list with class for complex types Pin
David Crow10-Jul-06 8:18
David Crow10-Jul-06 8:18 
GeneralRe: Sorting a list with class for complex types Pin
FarPointer10-Jul-06 8:26
FarPointer10-Jul-06 8:26 
GeneralRe: Sorting a list with class for complex types Pin
David Crow10-Jul-06 8:39
David Crow10-Jul-06 8:39 
GeneralRe: Sorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 7:35
Harold_Wishes10-Jul-06 7:35 
GeneralRe: Sorting a list with class for complex types Pin
FarPointer10-Jul-06 7:44
FarPointer10-Jul-06 7:44 
AnswerRe: Sorting a list with class for complex types Pin
earl10-Jul-06 9:29
earl10-Jul-06 9:29 
GeneralRe: Sorting a list with class for complex types Pin
Harold_Wishes10-Jul-06 10:49
Harold_Wishes10-Jul-06 10:49 
GeneralRe: Sorting a list with class for complex types Pin
earl10-Jul-06 11:14
earl10-Jul-06 11:14 
GeneralRe: Sorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 15:07
Harold_Wishes10-Jul-06 15:07 
GeneralRe: Sorting a list with class for complex types Pin
earl11-Jul-06 4:27
earl11-Jul-06 4:27 
AnswerRe: Sorting a list with class for complex types [modified] Pin
Stephen Hewitt10-Jul-06 14:45
Stephen Hewitt10-Jul-06 14:45 

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.