473,499 Members | 1,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About my own mem_fun1_ref_t.

This is just a exercise. I defined my own mem_fun1_ref_t in my_fun
space.
But got compiling error. How to fix it ? Any help is appreciated.

Administrator@HILL /m/tcplex/p3_ch18
$ cat mem_fun1_ref.cpp
#include <list>
#include <functional>
#include <iostream>
#include <algorithm>

namespace my_fun{
//class mem_fun1_ref_t
template<typename R, typename T, typename Targclass mem_fun1_ref_t:
public std::binary_function<T, Targ, R>
{
R (T::*pmf)(Targ);
public:
explicit mem_fun1_ref_t(R (T::*p)(Targ)):pmf(p){}
R operator()(T& p, Targ arg){return (p.*pmf)(arg);}
};
template<typename R, typename T, typename Targ>
mem_fun1_ref_t<R, T, Targmem_fun_ref(R (T::*f)(Targ))
{
return mem_fun1_ref_t<R, T, Targ>(f);
}
}//end namespace my_fun
class base
{
public:
void print_with(const std::string str){
std::cout << "Just for test: " << this << str << std::endl;
}
};
int main()
{
base bn;
std::string str("TEST_STRING");
std::bind2nd(my_fun::mem_fun_ref(&base::print_with ),str)(bn);
}
Administrator@HILL /m/tcplex/p3_ch18
$ g++ mem_fun1_ref.cpp
e:/opt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/
3.4.5/bits/stl_function.h: In member function `typename
_Operation::result_type std::binder2nd<_Operation>::operator()
(typename _Operation::first_argument_type&) const [with _Operation =
my_fun::mem_fun1_ref_t<void, base, std::string>]':
mem_fun1_ref.cpp:33: instantiated from here
e:/opt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/
3.4.5/bits/stl_function.h:446: error: passing `const
my_fun::mem_fun1_ref_t<void, base, std::string>' as `this' argument of
`R my_fun::mem_fun1_ref_t<R, T, Targ>::operator()(T&, Targ) [with R =
void, T = base, Targ = std::string]' discards qualifiers
Oct 23 '08 #1
2 1467
Hill wrote:
This is just a exercise. I defined my own mem_fun1_ref_t in my_fun
space.
But got compiling error. How to fix it ? Any help is appreciated.

Administrator@HILL /m/tcplex/p3_ch18
$ cat mem_fun1_ref.cpp
#include <list>
#include <functional>
#include <iostream>
#include <algorithm>

namespace my_fun{
//class mem_fun1_ref_t
template<typename R, typename T, typename Targclass mem_fun1_ref_t:
public std::binary_function<T, Targ, R>
{
R (T::*pmf)(Targ);
public:
explicit mem_fun1_ref_t(R (T::*p)(Targ)):pmf(p){}
R operator()(T& p, Targ arg){return (p.*pmf)(arg);}
Change this to:
R operator()(T& p, Targ arg)const{return (p.*pmf)(arg);}
----------------------------------^^^^^
};
template<typename R, typename T, typename Targ>
mem_fun1_ref_t<R, T, Targmem_fun_ref(R (T::*f)(Targ))
{
return mem_fun1_ref_t<R, T, Targ>(f);
}
}//end namespace my_fun
class base
{
public:
void print_with(const std::string str){
std::cout << "Just for test: " << this << str << std::endl;
}
};
int main()
{
base bn;
std::string str("TEST_STRING");
std::bind2nd(my_fun::mem_fun_ref(&base::print_with ),str)(bn);
}
Administrator@HILL /m/tcplex/p3_ch18
$ g++ mem_fun1_ref.cpp
e:/opt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/
3.4.5/bits/stl_function.h: In member function `typename
_Operation::result_type std::binder2nd<_Operation>::operator()
(typename _Operation::first_argument_type&) const [with _Operation =
my_fun::mem_fun1_ref_t<void, base, std::string>]':
mem_fun1_ref.cpp:33: instantiated from here
e:/opt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/
3.4.5/bits/stl_function.h:446: error: passing `const
my_fun::mem_fun1_ref_t<void, base, std::string>' as `this' argument of
`R my_fun::mem_fun1_ref_t<R, T, Targ>::operator()(T&, Targ) [with R =
void, T = base, Targ = std::string]' discards qualifiers
Oct 24 '08 #2
On 10ÔÂ24ÈÕ, ÏÂÎç4ʱ33·Ö, Bradley Smith <s...@baysmith.comwrote:
Hill wrote:
This is just a exercise. I defined my own mem_fun1_ref_t in my_fun
space.
But got compiling error. How to fix it ? Any help is appreciated.
Administrator@HILL /m/tcplex/p3_ch18
$ cat mem_fun1_ref.cpp
#include <list>
#include <functional>
#include <iostream>
#include <algorithm>
namespace my_fun{
//class mem_fun1_ref_t
template<typename R, typename T, typename Targclass mem_fun1_ref_t:
public std::binary_function<T, Targ, R>
{
R (T::*pmf)(Targ);
public:
explicit mem_fun1_ref_t(R (T::*p)(Targ)):pmf(p){}
R operator()(T& p, Targ arg){return (p.*pmf)(arg);}

Change this to:
R operator()(T& p, Targ arg)const{return (p.*pmf)(arg);}
----------------------------------^^^^^
};
template<typename R, typename T, typename Targ>
mem_fun1_ref_t<R, T, Targmem_fun_ref(R (T::*f)(Targ))
{
return mem_fun1_ref_t<R, T, Targ>(f);
}
}//end namespace my_fun
class base
{
public:
void print_with(const std::string str){
std::cout << "Just for test: " << this << str << std::endl;
}
};
int main()
{
base bn;
std::string str("TEST_STRING");
std::bind2nd(my_fun::mem_fun_ref(&base::print_with ),str)(bn);
}
Administrator@HILL /m/tcplex/p3_ch18
$ g++ mem_fun1_ref.cpp
e:/opt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/
3.4.5/bits/stl_function.h: In member function `typename
_Operation::result_type std::binder2nd<_Operation>::operator()
(typename _Operation::first_argument_type&) const [with _Operation =
my_fun::mem_fun1_ref_t<void, base, std::string>]':
mem_fun1_ref.cpp:33: instantiated from here
e:/opt/mingw/bin/../lib/gcc/mingw32/3.4.5/../../../../include/c++/
3.4.5/bits/stl_function.h:446: error: passing `const
my_fun::mem_fun1_ref_t<void, base, std::string>' as `this' argument of
`R my_fun::mem_fun1_ref_t<R, T, Targ>::operator()(T&, Targ) [with R =
void, T = base, Targ = std::string]' discards qualifiers- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -
Thanks very much :)
Oct 25 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2818
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
220
18799
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
54
6497
by: Brandon J. Van Every | last post by:
I'm realizing I didn't frame my question well. What's ***TOTALLY COMPELLING*** about Ruby over Python? What makes you jump up in your chair and scream "Wow! Ruby has *that*? That is SO...
8
2442
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
125
14536
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
5
2976
by: eScrewDotCom | last post by:
www.eScrew.com eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is...
0
2430
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
7
3120
by: Edward Yang | last post by:
A few days ago I started a thread "I think C# is forcing us to write more (redundant) code" and got many replies (more than what I had expected). But after reading all the replies I think my...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
664
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.