기본 콘텐츠로 건너뛰기

bind2nd 컴파일 오류

아래와 같은 소스에서 bind2nd에서 컴파일 오류가 난다.

#include <list>
#include <algorithm>
#include <functional>
using namespace std;

typedef struct mystorage
{
    int i;
    char c;
} mystorage;

typedef list<char*> mylist;

inline
bool
check(const mystorage& s, int id)
{
    return s.i == id;
}

int
main(int,char**)
{
    mylist lst;
    mylist::iterator ib;

    bind2nd(ptr_fun(check), 10);

    return 0;
}
아래는 컴파일과 오류이다.
$ g++ -c bind2nd.cpp
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h: In instantiation of ‘std::binder2nd<std::pointer_to_binary_function<const mystorage&, int, bool> >’:
/home/daldev/purewell/stuff/pwprj/src/bind2nd/main.cpp:27:   instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h:439: error: forming reference to reference type ‘const mystorage&’
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/stl_function.h:445: error: forming reference to reference type ‘const mystorage&’
보면 "forming reference to reference type"이라는 문구가 보이는데, 이는 레퍼런스를 레퍼런스하는 객체를 만들 수 없다는 것이다. "const mystorage&&" 같은 형태를 만들 수 없다는 말인데...

그럼 위 소스에서 find_if/for_each를 위해 비교 class를 만들어야하나!? 귀찮게스리...


덧글: 제길! 알려진 버그란다. 막고 품던지 boost 쓰라는데... 참조

Powered by ScribeFire.

댓글

이 블로그의 인기 게시물

탐색기에서 OneDrive 이 2개로 보이는 문제

왜 2개가 보이는지 모르겠지만, Registry 삭제하면 됨 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace 하위 키에서 OneDrive 둘 중에 하나만 지워도 바로 반영됨. 참조:  https://answers.microsoft.com/en-us/msoffice/forum/all/duplicate-onedrives-in-file-explorer/49c935a6-287b-43a5-aed5-2dee2a1c1b22