IWANTTOSUBMIT's blog

By IWANTTOSUBMIT, 13 years ago, In Russian

Доброго времени суток. :)

Возможно Вам покажется, что я - один из суперменов или идиотов, но всё же хочется задать такой вопрос:

Почему в GCC может не компилироваться сей код?

#include <vector>
#include <algorithm>

using namespace std;


typedef pair < pair < double, double > , pair < int , int > > WHAT_A_MAD_TYPE1111;
typedef WHAT_A_MAD_TYPE1111 my;

bool my_compare ( my & A, my & B )
{
   return true;
}

int main()
{
   vector < my > sorted;
   sort( sorted.begin(), sorted.end(), my_compare );
   return 0;
}

В 2005 студии же компилируется нормально.


Компилятор сообщает нам следующее:

Can't compile program.cpp:
In file included from c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/algorithm:62,
from program.cpp:2:
c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h: In function 'const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = std::pair<std::pair<double, double>, std::pair<int, int> >, _Compare = bool (*)(my&, my&)]':
c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:2301: instantiated from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<std::pair<std::pair<double, double>, std::pair<int, int> >*, std::vector<std::pair<std::pair<double, double>, std::pair<int, int> >, std::allocator<std::pair<std::pair<double, double>, std::pair<int, int> > > > >, _Size = int, _Compare = bool (*)(my&, my&)]'
c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:5258: instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<std::pair<std::pair<double, double>, std::pair<int, int> >*, std::vector<std::pair<std::pair<double, double>, std::pair<int, int> >, std::allocator<std::pair<std::pair<double, double>, std::pair<int, int> > > > >, _Compare = bool (*)(my&, my&)]'
program.cpp:16: instantiated from here
c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:124: error: invalid initialization of reference of type 'my&' from expression of type 'const std::pair<std::pair<double, double>, std::pair<int, int> >'
c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:125: error: invalid initialization of reference of type 'my&' from expression of type 'const std::pair<std::pair<double, double>, std::pair<int, int> >'
c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:127: error: invalid initialization of reference of type 'my&' from expression of type 'const std::pair<std::pair<double, double>, std::pair<int, int> >'
c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:131: error: invalid initialization of reference of type 'my&' from expression of type 'const std::pair<std::pair<double, double>, std::pair<int, int> >'
c:\compiler\mingw\bin\../lib/gcc/mingw32/4.4.1/include/c++/bits/stl_algo.h:133: error: invalid initialization of reference of type 'my&' from expression of type 'const std::pair<std::pair<double, double>, std::pair<int, int> >'


Заранее спасибо.

  • Vote: I like it
  • +6
  • Vote: I do not like it