Click here to Skip to main content
15,891,431 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionSorting a list with class for complex types [modified] Pin
Harold_Wishes10-Jul-06 5:26
Harold_Wishes10-Jul-06 5:26 
QuestionRe: Sorting a list with class for complex types Pin
David Crow10-Jul-06 5:31
David Crow10-Jul-06 5:31 
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 
Well, I hate to place it here, but there were 14 errors. OMG | :OMG:

C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(23) : 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(23) : error C2133: 'mylist' : unknown size
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(23) : error C2512: 'list' : no appropriate default constructor available
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(23) : error C2262: 'mylist' : cannot be destroyed
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(28) : error C2662: 'push_back' : cannot convert 'this' pointer from 'class std::list' to 'class std::list<_Ty,_A> &'
Reason: cannot convert from 'class std::list' to 'class std::list<_Ty,_A>'
Conversion requires a second user-defined-conversion operator or constructor
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(30) : error C2662: 'push_back' : cannot convert 'this' pointer from 'class std::list' to 'class std::list<_Ty,_A> &'
Reason: cannot convert from 'class std::list' to 'class std::list<_Ty,_A>'
Conversion requires a second user-defined-conversion operator or constructor
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(33) : error C2663: 'sort' : 2 overloads have no legal conversion for 'this' pointer
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 C2663: 'begin' : 2 overloads have no legal conversion for 'this' pointer
C:\Documents and Settings\WoodallH\Desktop\C++\Project 6 Nesty tag\Sort.cpp(36) : error C2512: 'const_iterator' : no appropriate default constructor available
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 C2663: 'end' : 2 overloads have no legal conversion for 'this' pointer
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 - 14 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 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 13:48 Monday 10th July, 2006
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 
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 

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.