class Student
{
public:
Student()
{ cout<<"\n" << __FUNCTION__; }
Student(int roolNo ):_rolNo( roolNo )
{ cout<<"\n" << __FUNCTION__; }
~Student()
{ cout<<"\n" << __FUNCTION__; }
/*
bool toAssending( Student & s1 , Student & s2 )
{
cout<<"\n" << __FUNCTION__;
return s1.getRollNo() < s2.getRollNo();
}*/
int getRollNo() const
{
return _rolNo;
}
private :
int _rolNo;
};
bool toAssending( const Student & s1 , const Student & s2 )
{
cout<<"\n" << __FUNCTION__;
return s1.getRollNo() < s2.getRollNo();
}
int main()
{
QList<Student*> studentList ;
studentList.append( new Student(2) );
studentList.append( new Student(4) );
studentList.append( new Student(3) );
studentList.append( new Student(1) );
studentList.append( new Student(5) );
QListIterator<Student*> it( studentList );
Student* val = 0;
cout<<"\n ****** Before SORT ***** " ;
while( it.hasNext() )
{
val = it.next();
//cout<<"\n" << val;
cout<<"\n" << val->getRollNo();
}
qSort( studentList.begin() , studentList.end(), toAssending ); //here am using the global function. instead of class -member function.
cout<<"\n ****** After SORT ***** " ;
QListIterator<Student*> it_1( studentList );
Student* val_1 = 0;
while( it_1.hasNext() )
{
val_1 = it_1.next();
cout<<"\n" << val_1;
cout<<"\n" << val_1->getRollNo();
}
qDeleteAll( studentList );
return 0;
}
class Student
{
public:
Student()
{ cout<<"\n" << __FUNCTION__; }
Student(int roolNo ):_rolNo( roolNo )
{ cout<<"\n" << __FUNCTION__; }
~Student()
{ cout<<"\n" << __FUNCTION__; }
/*
bool toAssending( Student & s1 , Student & s2 )
{
cout<<"\n" << __FUNCTION__;
return s1.getRollNo() < s2.getRollNo();
}*/
int getRollNo() const
{
return _rolNo;
}
private :
int _rolNo;
};
bool toAssending( const Student & s1 , const Student & s2 )
{
cout<<"\n" << __FUNCTION__;
return s1.getRollNo() < s2.getRollNo();
}
int main()
{
QList<Student*> studentList ;
studentList.append( new Student(2) );
studentList.append( new Student(4) );
studentList.append( new Student(3) );
studentList.append( new Student(1) );
studentList.append( new Student(5) );
QListIterator<Student*> it( studentList );
Student* val = 0;
cout<<"\n ****** Before SORT ***** " ;
while( it.hasNext() )
{
val = it.next();
//cout<<"\n" << val;
cout<<"\n" << val->getRollNo();
}
qSort( studentList.begin() , studentList.end(), toAssending ); //here am using the global function. instead of class -member function.
cout<<"\n ****** After SORT ***** " ;
QListIterator<Student*> it_1( studentList );
Student* val_1 = 0;
while( it_1.hasNext() )
{
val_1 = it_1.next();
cout<<"\n" << val_1;
cout<<"\n" << val_1->getRollNo();
}
qDeleteAll( studentList );
return 0;
}
To copy to clipboard, switch view to plain text mode
main.cpp(311) : warning C4101: 'assending' : unreferenced local variable
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(355) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(180) : see reference to function template instantiation 'void QAlgorithmsPrivate::qSortHelper<RandomAccessIterator,T,bool(__cdecl *)(const Student &,const Student &)>(RandomAccessIterator,RandomAccessIterator,const T & ,LessThan)' being compiled
with
[
RandomAccessIterator=QList<Student *>::iterator,
T=Student *,
LessThan=bool (__cdecl *)(const Student &,const Student &)
]
main.cpp(312) : see reference to function template instantiation 'void qSort<QList<T>::iterator,bool(__cdecl *)(const Student &,const Student &)>(RandomAccessIterator,RandomAccessIterator,LessThan)' being compiled
with
[
T=Student *,
RandomAccessIterator=QList<Student *>::iterator,
LessThan=bool (__cdecl *)(const Student &,const Student &)
]
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(355) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(360) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(360) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(362) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(362) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(370) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(370) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(373) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(373) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(385) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(385) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
logFile - 12 error(s), 10 warning(s)
main.cpp(311) : warning C4101: 'assending' : unreferenced local variable
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(355) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(180) : see reference to function template instantiation 'void QAlgorithmsPrivate::qSortHelper<RandomAccessIterator,T,bool(__cdecl *)(const Student &,const Student &)>(RandomAccessIterator,RandomAccessIterator,const T & ,LessThan)' being compiled
with
[
RandomAccessIterator=QList<Student *>::iterator,
T=Student *,
LessThan=bool (__cdecl *)(const Student &,const Student &)
]
main.cpp(312) : see reference to function template instantiation 'void qSort<QList<T>::iterator,bool(__cdecl *)(const Student &,const Student &)>(RandomAccessIterator,RandomAccessIterator,LessThan)' being compiled
with
[
T=Student *,
RandomAccessIterator=QList<Student *>::iterator,
LessThan=bool (__cdecl *)(const Student &,const Student &)
]
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(355) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(360) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(360) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(362) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(362) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(370) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(370) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(373) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(373) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(385) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 2 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\Qt\4.2.2\include\QtCore\../../src\corelib\tools\qalgorithms.h(385) : error C2664: 'bool (const Student &,const Student &)' : cannot convert parameter 1 from 'Student *' to 'const Student &'
Reason: cannot convert from 'Student *' to 'const Student'
No constructor could take the source type, or constructor overload resolution was ambiguous
logFile - 12 error(s), 10 warning(s)
To copy to clipboard, switch view to plain text mode
Bookmarks