Z
zhang.yongpeng
Hello, I met some problems when trying to sort a list that has
shared_ptr in it. here is the non-compliable code.
test.cpp:
/********************* begin of code *************************/
#include <boost/shared_ptr.hpp>
#include <list>
class T{ // simplified this class to the simplest form
public:
T(int t):capacity(t){}
int capacity;
};
// I want to use this function as the third argument for sort() in
main.
bool capacityCompare(boost::shared_ptr<T> &lhs, boost::shared_ptr<T>
&rhs) // line 9
{
return (lhs->capacity < rhs->capacity);
}
int main()
{
boost::shared_ptr<T> T1 (new T(2));
boost::shared_ptr<T> T2 (new T(3));
list<boost::shared_ptr<T> > TList; // a list that consists of ptrs
TList.push_back(T1);
TList.push_back(T2);
sort(TList.begin(), TList.end(), capacityCompare()); // line 21
return 1;
}
/*************** end of code ************/
/****** the first compilig error **********/
test.cpp: In function `int main()':
test.cpp:9: error: too few arguments to function 'bool
capacityCompare(boost::shared_ptr<T>&, boost::shared_ptr<T>&)'
test.cpp:21: error: at this point in file
**********************************************************
Does anybody see what's wrong here? My guess is that the type of the
argument in capacityCompare() is wrong. If I am correct, how should I
define such a pred function?
BTW, compiler also has a warning:
/usr/include/gcc/darwin/4.0/c++/backward/backward_warning.h:32:2:
warning: #warning This file includes at least one deprecated or
antiquated header. Please consider using one of the 32 headers found in
section 17.4.1.2 of the C++ standard. Examples include substituting the
<X> header for the <X.h> header for C++ includes, or <iostream> instead
of the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
How can I get rid of it?
Thanks a lot.
P.S. The command that I use is:
g++ -Wall -g -I/usr/local/lib/boost_1_33_1 test.cpp
shared_ptr in it. here is the non-compliable code.
test.cpp:
/********************* begin of code *************************/
#include <boost/shared_ptr.hpp>
#include <list>
class T{ // simplified this class to the simplest form
public:
T(int t):capacity(t){}
int capacity;
};
// I want to use this function as the third argument for sort() in
main.
bool capacityCompare(boost::shared_ptr<T> &lhs, boost::shared_ptr<T>
&rhs) // line 9
{
return (lhs->capacity < rhs->capacity);
}
int main()
{
boost::shared_ptr<T> T1 (new T(2));
boost::shared_ptr<T> T2 (new T(3));
list<boost::shared_ptr<T> > TList; // a list that consists of ptrs
TList.push_back(T1);
TList.push_back(T2);
sort(TList.begin(), TList.end(), capacityCompare()); // line 21
return 1;
}
/*************** end of code ************/
/****** the first compilig error **********/
test.cpp: In function `int main()':
test.cpp:9: error: too few arguments to function 'bool
capacityCompare(boost::shared_ptr<T>&, boost::shared_ptr<T>&)'
test.cpp:21: error: at this point in file
**********************************************************
Does anybody see what's wrong here? My guess is that the type of the
argument in capacityCompare() is wrong. If I am correct, how should I
define such a pred function?
BTW, compiler also has a warning:
/usr/include/gcc/darwin/4.0/c++/backward/backward_warning.h:32:2:
warning: #warning This file includes at least one deprecated or
antiquated header. Please consider using one of the 32 headers found in
section 17.4.1.2 of the C++ standard. Examples include substituting the
<X> header for the <X.h> header for C++ includes, or <iostream> instead
of the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
How can I get rid of it?
Thanks a lot.
P.S. The command that I use is:
g++ -Wall -g -I/usr/local/lib/boost_1_33_1 test.cpp