bind2nd question

B

benben

I wrote the following lines:

#include <locale>
#include <functional>
#include <algorithm>

int main()
{
using namespace std;
bind2nd(ptr_fun(tolower<char>), locale());
}

and I got the following errors

g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"plotter.d"
-MT"plotter.d" -o"plotter.o" "../plotter.cpp"
/usr/include/c++/4.1.3/bits/stl_function.h: In instantiation of
‘std::binder2nd<std::pointer_to_binary_function<char, const
std::locale&, char> >’:
.../plotter.cpp:14: instantiated from here
/usr/include/c++/4.1.3/bits/stl_function.h:435: error: forming reference
to reference type ‘const std::locale&’
/usr/include/c++/4.1.3/bits/stl_function.h: In function
‘std::binder2nd<_Operation> std::bind2nd(const _Operation&, const _Tp&)
[with _Operation = std::pointer_to_binary_function<char, const
std::locale&, char>, _Tp = std::locale]’:
.../plotter.cpp:14: instantiated from here
/usr/include/c++/4.1.3/bits/stl_function.h:455: error: no matching
function for call to
‘std::binder2nd<std::pointer_to_binary_function<char, const
std::locale&, char> >::binder2nd(const
std::pointer_to_binary_function<char, const std::locale&, char>&, const
std::locale&)’
/usr/include/c++/4.1.3/bits/stl_function.h:429: note: candidates are:
std::binder2nd<std::pointer_to_binary_function<char, const std::locale&,
char> >::binder2nd(const
std::binder2nd<std::pointer_to_binary_function<char, const std::locale&,
char> >&)

Sorry but I've tried my best to understand the error message. I have no
idea why

"forming reference to reference type 'const std::locale&'"

is an error. Or is the error elsewhere?

Regards,
Ben
 
V

Victor Bazarov

benben said:
I wrote the following lines:

#include <locale>
#include <functional>
#include <algorithm>

int main()
{
using namespace std;
bind2nd(ptr_fun(tolower<char>), locale());
}

and I got the following errors

g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"plotter.d"
-MT"plotter.d" -o"plotter.o" "../plotter.cpp"
/usr/include/c++/4.1.3/bits/stl_function.h: In instantiation of
‘std::binder2nd<std::pointer_to_binary_function<char, const
std::locale&, char> >’:
../plotter.cpp:14: instantiated from here
/usr/include/c++/4.1.3/bits/stl_function.h:435: error: forming
reference to reference type ‘const std::locale&’
/usr/include/c++/4.1.3/bits/stl_function.h: In function
‘std::binder2nd<_Operation> std::bind2nd(const _Operation&, const
_Tp&) [with _Operation = std::pointer_to_binary_function<char, const
std::locale&, char>, _Tp = std::locale]’:
../plotter.cpp:14: instantiated from here
/usr/include/c++/4.1.3/bits/stl_function.h:455: error: no matching
function for call to
‘std::binder2nd<std::pointer_to_binary_function<char, const
std::locale&, char> >::binder2nd(const
std::pointer_to_binary_function<char, const std::locale&, char>&,
const std::locale&)’
/usr/include/c++/4.1.3/bits/stl_function.h:429: note: candidates are:
std::binder2nd<std::pointer_to_binary_function<char, const
std::locale&, char> >::binder2nd(const
std::binder2nd<std::pointer_to_binary_function<char, const
std::locale&, char> >&)

Sorry but I've tried my best to understand the error message. I have
no idea why

"forming reference to reference type 'const std::locale&'"

is an error. Or is the error elsewhere?

No, the error is right there.

There can be no reference to a reference in C++. References are not
objects. References can only refer to objects.

typedef int &rint;
int main() {
int a;
rint ra = a; // OK
rint & rra = ra; // not OK
}

'std::bind2nd' suffers from trying to create a reference to reference
when forming the argument type from a function that already takes
a reference to [const] object as its argument. Or something like that.

V
 
B

benben

'std::bind2nd' suffers from trying to create a reference to reference
when forming the argument type from a function that already takes
a reference to [const] object as its argument. Or something like that.

Thanks Victor! That makes a lot of sense now.

Regards,
Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top