T
tuko
Hello kind people.
The folliowing code gives me a compilation error, under
MSVC 6.0 and intel 8.0 compiler. It compiles fine with
g++ 3.3.1 and borland 5.5
Can you tell me please if the code is correct?.
If the code is correct do you know any tip
to "circumvent" the compilation error?
I want just to sort a list of CTimeFunction::timeFunc
objects having as key the t_ member.
Many thanks for your time.
Here is the code
// --------------------------------------------------
#include <algorithm> // Line 2
#include <list>
//
class CTimeFunction {
public:
struct timeFunc {
double t_, f_;
timeFunc () : t_(0.0), f_(0.0) {}
timeFunc (double t, double f) : t_(t), f_(f) {};
};
};
//
bool sort_by_time(const CTimeFunction::timeFunc &a, const CTimeFunction::timeFunc &b) {
return a.t_<b.t_;
}
//
int main () {
std::list<CTimeFunction::timeFunc> m_tim;
//
CTimeFunction::timeFunc mt(0.0, 1.0);
m_tim.push_back(mt); // <--- Error Here (line 24)
//
m_tim.sort(sort_by_time);
//
}
// End of Code.
Here is the error message
test.cpp(24): error: no instance of overloaded function
"std::list<_Ty, _A>::sort [with _Ty=CTimeFunction::timeFunc,
_A=std::allocator<CTimeFunction::timeFunc>]" matches the argument list
argument types are: (bool (const CTimeFunction::timeFunc &, const CT
imeFunction::timeFunc &))
object type is: std::list<CTimeFunction::timeFunc, std::allocator<CT
imeFunction::timeFunc>>
m_tim.sort(sort_by_time);
^
compilation aborted for test.cpp (code 2)
The folliowing code gives me a compilation error, under
MSVC 6.0 and intel 8.0 compiler. It compiles fine with
g++ 3.3.1 and borland 5.5
Can you tell me please if the code is correct?.
If the code is correct do you know any tip
to "circumvent" the compilation error?
I want just to sort a list of CTimeFunction::timeFunc
objects having as key the t_ member.
Many thanks for your time.
Here is the code
// --------------------------------------------------
#include <algorithm> // Line 2
#include <list>
//
class CTimeFunction {
public:
struct timeFunc {
double t_, f_;
timeFunc () : t_(0.0), f_(0.0) {}
timeFunc (double t, double f) : t_(t), f_(f) {};
};
};
//
bool sort_by_time(const CTimeFunction::timeFunc &a, const CTimeFunction::timeFunc &b) {
return a.t_<b.t_;
}
//
int main () {
std::list<CTimeFunction::timeFunc> m_tim;
//
CTimeFunction::timeFunc mt(0.0, 1.0);
m_tim.push_back(mt); // <--- Error Here (line 24)
//
m_tim.sort(sort_by_time);
//
}
// End of Code.
Here is the error message
test.cpp(24): error: no instance of overloaded function
"std::list<_Ty, _A>::sort [with _Ty=CTimeFunction::timeFunc,
_A=std::allocator<CTimeFunction::timeFunc>]" matches the argument list
argument types are: (bool (const CTimeFunction::timeFunc &, const CT
imeFunction::timeFunc &))
object type is: std::list<CTimeFunction::timeFunc, std::allocator<CT
imeFunction::timeFunc>>
m_tim.sort(sort_by_time);
^
compilation aborted for test.cpp (code 2)