Connecting Tech Pros Worldwide Help | Site Map

A compilation error.

  #1  
Old July 22nd, 2005, 05:38 PM
tuko
Guest
 
Posts: n/a
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)

--
tuko, the mexican - the ugly fellow
  #2  
Old July 22nd, 2005, 05:38 PM
tuko
Guest
 
Posts: n/a

re: A compilation error.


tuko wrote:

< snip >

I think I did it finally. My mind was stopped...
I overloaded the operator< and I called the sort like
m_tim.sort();
[color=blue]
>
> 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_;
> }[/color]

bool operator<(const CTimeFunction::timeFunc &a,
const CTimeFunction::timeFunc &b) {
return a.t_<b.t_;
}
[color=blue]
> //
> 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);[/color]

m_tim.sort();[color=blue]
> //
> }
>
> // 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)
>[/color]

Thanks for your time anyway.

--
tuko, the mexican - the ugly fellow

  #3  
Old July 22nd, 2005, 05:39 PM
David Hilsee
Guest
 
Posts: n/a

re: A compilation error.



"tuko" <tuko@away.com> wrote in message news:cdh267$iaq$1@nic.grnet.gr...[color=blue]
> tuko wrote:
>
> < snip >
>
> I think I did it finally. My mind was stopped...
> I overloaded the operator< and I called the sort like
> m_tim.sort();
>[/color]

Keep in mind that the std::list::sort() implementation provided by VC++6.0
has a bug. See http://www.dinkumware.com/vc_fixes.html for more
information.

Also, unless you have a specific reason for using a std::list, I would
recommend using a std::vector and sorting it with std::sort in the header
<algorithm>.

--
David Hilsee


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Functor Compilation Error BSand0764@msn.com answers 1 November 8th, 2007 07:35 PM
Odd 'Compilation Error' when viewing aspx page on server Stimp answers 0 September 19th, 2006 02:55 PM
Programmatically retrieving ASPX Compilation Error details Plat answers 6 March 7th, 2006 06:35 PM
Weird Compilation Error Migrating from Dreamweaver to VS James Zhuo answers 0 November 17th, 2005 09:14 PM
ASP.NET page compilation error Joachim answers 6 November 17th, 2005 12:05 AM