Quote Originally Posted by lmpb17 View Post
I dont really see how that would cause a compile error
Here is your code compiled with Comeau:
Code:
Thank you for testing your code with Comeau C/C++!
Tell others about http://www.comeaucomputing.com/tryitout !

Your Comeau C/C++ test results are as follows:

Comeau C/C++ 4.3.10.1 (Oct  6 2008 11:28:09) for ONLINE_EVALUATION_BETA2
Copyright 1988-2008 Comeau Computing.  All rights reserved.
MODE:strict errors C++ C++0x_extensions

"concept_checks.h", line 329: error: qualifiers dropped in binding
          reference of type "Job &" to initializer of type "const Job"
      return __f(__first, __second);
                 ^
          detected during:
            instantiation of "_Ret _STL_BINARY_FUNCTION_ERROR<_Func, _Ret,
                      _First,
                      _Second>::__binary_function_requirement_violation(_Func
                      &, const _First &, const _Second &) [with _Func=bool
                      (*)(Job &, Job &), _Ret=bool, _First=Job, _Second=Job]"
                      at line 1552 of "stl_algo.h"
            instantiation of "void std::sort(_RandomAccessIter,
                      _RandomAccessIter, _Compare) [with _RandomAccessIter=Job
                      *, _Compare=bool (*)(Job &, Job &)]" at line 102 of
                      "ComeauTest.c"

"concept_checks.h", line 329: error: qualifiers dropped in binding
          reference of type "Job &" to initializer of type "const Job"
      return __f(__first, __second);
                          ^
          detected during:
            instantiation of "_Ret _STL_BINARY_FUNCTION_ERROR<_Func, _Ret,
                      _First,
                      _Second>::__binary_function_requirement_violation(_Func
                      &, const _First &, const _Second &) [with _Func=bool
                      (*)(Job &, Job &), _Ret=bool, _First=Job, _Second=Job]"
                      at line 1552 of "stl_algo.h"
            instantiation of "void std::sort(_RandomAccessIter,
                      _RandomAccessIter, _Compare) [with _RandomAccessIter=Job
                      *, _Compare=bool (*)(Job &, Job &)]" at line 102 of
                      "ComeauTest.c"

"stl_algo.h", line 135: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
    if (__comp(__a, __b))
               ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 135: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
    if (__comp(__a, __b))
                    ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 136: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
      if (__comp(__b, __c))
                 ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 136: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
      if (__comp(__b, __c))
                      ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 138: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
      else if (__comp(__a, __c))
                      ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 138: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
      else if (__comp(__a, __c))
                           ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 142: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
    else if (__comp(__a, __c))
                    ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 142: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
    else if (__comp(__a, __c))
                         ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 144: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
    else if (__comp(__b, __c))
                    ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

"stl_algo.h", line 144: error: qualifiers dropped in binding reference of
          type "Job &" to initializer of type "const Job"
    else if (__comp(__b, __c))
                         ^
          detected during:
            instantiation of "const _Tp &std::__median(const _Tp &, const _Tp
                      &, const _Tp &, _Compare) [with _Tp=Job, _Compare=bool
                      (*)(Job &, Job &)]" at line 1525
            instantiation of "void std::__introsort_loop(_RandomAccessIter,
                      _RandomAccessIter, _Tp *, _Size, _Compare) [with
                      _RandomAccessIter=Job *, _Tp=Job, _Size=int,
                      _Compare=bool (*)(Job &, Job &)]" at line 1556

12 errors detected in the compilation of "ComeauTest.c".

In strict mode, with -tused, Compile failed
The std::sort is expecting your function to be using const arguments. Your functions violated this rule. The reason why Visual C++ doesn't give you an error is either the compiler is wrong, or it is strictly pure luck of how the VC++ std::sort is implemented when it calls your function. If you compiled with the highest warning level, you may see the same diagnostic.

As you can clearly see that other compilers (Comeau) give similar errors. Possibly, the next version of VC++ will also not let you get away with it, and will reject your code.

Second, do not put "using namespace std" in a header file. The reason is that any module that includes that header has the whole std namespace forced upon it. Instead, prepend "std::" to those identifiers in the header file.

Regards,

Paul McKenzie