| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"benben benhonghatgmaildotcom@nospam" |
| Date: |
07 Nov 2007 10:34:08 AM |
| Object: |
bind2nd question |
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
.
|
|
| User: "Victor Bazarov" |
|
| Title: Re: bind2nd question |
07 Nov 2007 10:44:06 AM |
|
|
benben wrote:
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
.
|
|
|
| User: "benben benhonghatgmaildotcom@nospam" |
|
| Title: Re: bind2nd question |
08 Nov 2007 05:38:02 AM |
|
|
'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
.
|
|
|
|
|

|
Related Articles |
|
|