[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

About my own mem_fun1_ref_t.

Hill

10/23/2008 5:58:00 PM

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 Targ> class 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, Targ> mem_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
4 Answers

Bradley Smith

10/24/2008 8:34:00 AM

0

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 Targ> class 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, Targ> mem_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

Hill

10/25/2008 1:28:00 AM

0

On 10?24?, ??4?33?, Bradley Smith <s...@baysmith.com> wrote:
> 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 Targ> class 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, Targ> mem_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 :)

KenH

2/17/2011 7:24:00 PM

0

> Is the ROM code it in the 6530 known?  With a moderate amount of work
> a microcontroller could emulate a 6530 with a small card that plugs
> into the 6530 socket.

John from flippers.com was working on a board, but it never made it
past the design stage, possibly due to there being little demand for
the product. If someone has extracted the code, no one has made it
available to my knowledge.

pinballpsycho

2/18/2011 3:46:00 PM

0

On Feb 17, 2:23 pm, KenH <klhuber2...@yahoo.com> wrote:
> > Is the ROM code it in the 6530 known?  With a moderate amount of work
> > a microcontroller could emulate a 6530 with a small card that plugs
> > into the 6530 socket.
>
> John from flippers.com was working on a board, but it never made it
> past the design stage, possibly due to there being little demand for
> the product.  If someone has extracted the code, no one has made it
> available to my knowledge.

Are you guys talking about "Rock On"?

Been wanting to get my hands on one of those myself.