<algorithm> 에 sort 함수를 사용하려고 하는데요

xe11oss의 이미지

솔라리스에서 컴파일을 하고 있는데 안되거든요;
g++은
bash-3.00# g++ -v
Reading specs from /usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --enable-shared --enable-languages=c,c++,f77
Thread model: posix
gcc version 3.4.6
이렇고요
컴파일하면 에러내용이
/usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h: In function `const _Tp& std::__median(const _Tp&, const _Tp&, const _Tp&, _Compare) [with _Tp = int, _Compare = bool (*)(int&, int&)]':
/usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:2519: instantiated from `void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Size = int, _Compare = bool (*)(int&, int&)]'
/usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:2589: instantiated from `void std::sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator > >, _Compare = bool (*)(int&, int&)]'
Test.cpp:57: instantiated from here
/usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:124: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
/usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:125: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
/usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:127: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
/usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:131: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
/usr/local/lib/gcc/i386-pc-solaris2.10/3.4.6/../../../../include/c++/3.4.6/bits/stl_algo.h:133: error: invalid initialization of reference of type 'int&' from expression of type 'const int'
이렇고요
소스는 간단한 성적받아서 sort하는거에요
#include

#include

#include

using namespace std;

bool isBigger( int& a, int& b);

int main()

{

int num;

vector It;//리스트 객체 생성

while(true)

{

cout << "성적을 입력하세요 (-1을 입력하면 종료) : ";

cin >> num;

if(num == -1)

break;

if(num < 0 || num > 100)

{

cout << "0에서 100사이의 값을 입력하세요.\n";

continue;

}

It.push_back(num);//리스트에 데이터 추가

}

int sum = 0;

sort( It.begin(), It.end(), isBigger);

//It.sort();//리스트의 항목을 오름차순으로 정렬

cout << "입력된 점수(오름차순) : ";

vector::iterator it;

for(it = It.begin(); it != It.end(); ++it)

{

sum += (*it);

cout << (*it) << " ";

}

double average = (double) sum / It.size();

cout<<"\n학생수 : " << It.size() << "명, 평균 : " << average << "점\n";

return 0;

}

bool isBigger( int& a, int& b)

{

if( a>= b)

{

return true;

}

else

{

return false;

}

}

Fe.head의 이미지

bool isBigger( const int& a, constint& b)

이렇게 하니 되네요.

아마 컨테이너 안에서 값을 복사가 원칙인걸로 아는데 그것때문이지 않을까 생각되네요.
-----------------------
과거를 알고 싶거든 오늘의 네 모습을 보아라. 그것이 과거의 너니라.
그리고 내일을 알고 싶으냐?
그러면 오늘의 너를 보아라. 그것이 바로 미래의 너니라.

고작 블로킹 하나, 고작 25점 중에 1점, 고작 부활동
"만약 그 순간이 온다면 그때가 네가 배구에 빠지는 순간이야"

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.