Topic: HELP with mem_fun() and bind2nd() PLEASE!


Author: frank_tripp@hotmail.com (Frank Tripp)
Date: 1998/11/05
Raw View
Dear c++ gurus,

I tried to compile this simple test program with MC Visual c++ 5.0.
I get wierd error:

C:\Program Files\DevStudio\VC\INCLUDE\functional(178) : error C2662:
'()' : cannot convert 'this' pointer from 'const class
std::mem_fun1_t<int,class Shape,float>' to 'class
std::mem_fun1_t<int,class Shape,float> &'
 Conversion loses qualifiers

It seems that the only way to get rid of the error is to EDIT
<functional> and remove the "const". What gives?

If I use mem_fun() instead of mem_fun1() (just like the example on
page 521 of "The C++ Programming Language 3rd Edition" (Stroustrup),
I get the following error:

D:\test\test\main.cpp(31) : error C2784: 'class
std::mem_fun_t<`template-parameter-1',`template-parameter-2'> __cdecl
std::mem_fun(template-parameter-1 (template-parameter::*)(void))' :
could not deduce template argument for 'template-parameter-1
(template-parameter::*)(void)' from 'int (Shape::*)(float)'


Here is the source:


#include <functional>
#include <algorithm>
#include <list>

using namespace std;

class Shape
{
public:
 int x;

 // rotate function does nothing...
 int rotate(float angle)
 {
  int rr = x;
  return 1; }
};

int main()
{
 float angle=60.0;
 Shape shape1, shape2;
 shape1.x = 5;
 shape2.x = 6;

 list<Shape*>ls;

 ls.push_back(&shape1);
 ls.push_back(&shape2);

 for_each(ls.begin(), ls.end(),
bind2nd(mem_fun1(&Shape::rotate), angle));

 return 0;
}
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: jcoffin@taeus.com (Jerry Coffin)
Date: 1998/11/06
Raw View
In article <363f920e.57084718@news.cwix.com>, frank_tripp@hotmail.com
says...
> Dear c++ gurus,
>
> I tried to compile this simple test program with MC Visual c++ 5.0.
> I get wierd error:

You might want to consider an upgrade to VC++ 6.0 -- it compiles your
code with no problems...
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]