기본 콘텐츠로 건너뛰기

라벨이 bind2nd인 게시물 표시

bind2nd 컴파일 오류2

bind2nd 컴파일 오류 아, 시바스 리갈 같은 상황. 이럴꺼면 뭣하러 STL써! #include <list> #include <algorithm> #include <functional> #include <iostream> using namespace std; typedef struct mystorage { int i; char c; } mystorage; #if defined(POINTER_TYPE) typedef list<mystorage*> mylist; #else typedef list<mystorage> mylist; #endif #if defined(POINTER_TYPE) inline bool check(const mystorage* _s, int id) { const mystorage& s(*_s); #else inline bool check(const mystorage s, int id) // You can't use below function type. // Standard C++ does not support ref of ref. //check(const mystorage& s, int id) { #endif return s.i == id; } void addList(mylist& lst) { for ( size_t i(0); i<1000; i++ ) { #if defined(POINTER_TYPE) lst.push_front(new mystorage); mystorage& s(**lst.begin()); #else lst.push_front(mystorage()); mystorage& s(*lst.begin()); #endif s.i = i; s.c = i%26+'A';...

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_func...