About the third parameter of std::sort in VC6.

7

77123036

why this programme cannot be built in vc6(there are two link error),but
successful in gcc?

------------------
#include <iostream>
#include <algorithm>

template <class T>
inline bool less(T _a, T _b)
{
return _a < _b;
}

int main(void)
{
int a[10] = {65, 23, 654, 87, 12, 56, 231, 15, 58, 78};
std::sort(a, a + 10, ::less<int>);
return 0;
}
------------------

And this is successful in vc6 and gcc:

------------------
#include <iostream>
#include <algorithm>

inline bool less(int _a, int _b)
{
return _a < _b;
}

int main(void)
{
int a[10] = {65, 23, 654, 87, 12, 56, 231, 15, 58, 78};
std::sort(a, a + 10, ::less);
return 0;
}
------------------
 
V

Victor Bazarov

why this programme cannot be built in vc6(there are two link
error),but successful in gcc?
[..]

Compiler-specific questions should be asked in the compiler
newsgroup (microsoft.public.vc.language in your case). VC6
is too old a compiler to talk about here anyway. Please
upgrade to VC7.1.

V
 
U

Uenal Mutlu

why this programme cannot be built in vc6(there are two link error),but
successful in gcc?

------------------
#include <iostream>
#include <algorithm>

template <class T>
inline bool less(T _a, T _b)
{
return _a < _b;
}

int main(void)
{
int a[10] = {65, 23, 654, 87, 12, 56, 231, 15, 58, 78};
std::sort(a, a + 10, ::less<int>);
return 0;
}
------------------

Try this:

#include <iostream>
#include <algorithm>

template<typename T> struct CmpLess
{
explicit CmpLess() {}
bool operator()(const T& lhs, const T& rhs) const
{ return lhs < rhs; }
};

int main(void)
{
int a[10] = {65, 23, 654, 87, 12, 56, 231, 15, 58, 78};
std::sort(a, a + 10, CmpLess<int>());
return 0;
}
 
R

Rapscallion

why this programme cannot be built in vc6(there are two link error),but
successful in gcc?
template <class T>
inline bool less(T _a, T _b)
{
return _a < _b;
}
std::sort(a, a + 10, ::less<int>);

because it probably conflicts with std::less, especially if you use a
'using namespace std;' somewhere.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top