473,320 Members | 1,600 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

mem_fun and C2784 using Ms VC++

Can anyone tell how to fix the compile error for the program below?

#include "iostream.h"
#include <vector>
#include <algorithm>
#include <functional>
#include <list>

using namespace std;

class Widget
{
};

class B
{
public:
bool IsInteresting(Widget) {return true;}
};

class C
{
public:
void Find(B b)
{
list<Widget>::iterator i = find_if(m_widgets.begin(),m_widgets.end(),
mem_fun_ref((*this).IsInteresting));
}
private:
list<Widget>m_widgets;
bool IsInteresting(const Widget widget) {return true;}
};

void main(void)
{};

Jul 22 '05 #1
9 2795
Mr X wrote:
Can anyone tell how to fix the compile error for the program below?

#include "iostream.h"'
Ugh!

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <list>

using namespace std;

class Widget
{
};

class B
{
public:
bool IsInteresting(Widget) {return true;}
};

class C
{
public:
void Find(B b)
{
list<Widget>::iterator i = find_if(m_widgets.begin(),m_widgets.end(),
mem_fun_ref((*this).IsInteresting));
Shouldn't this be

mem_fun_ref(&C::IsInteresting)

?
}
private:
list<Widget>m_widgets;
bool IsInteresting(const Widget widget) {return true;}
};

void main(void)
Yuck!
{};


Bleh!
Jul 22 '05 #2
This doesn't work either: (can someone come up with something that
does?)

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <list>

using namespace std;

class Widget
{};

class B
{};

class C
{
public:
void Find(B b)
{
Widget widget;
std::find_if(m_widgets.begin(),m_widgets.end(),std ::bind2nd(std::mem_fun(&C::IsInteresting),widget)) ;
}
private:
bool IsInteresting(Widget) {return true;}
list<Widget>m_widgets;
};

Jul 22 '05 #3
Mr X wrote:
This doesn't work either: (can someone come up with something that
does?)

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <list>

using namespace std;

class Widget
{};

class B
{};

class C
{
public:
void Find(B b)
{
Widget widget;
std::find_if(m_widgets.begin(),m_widgets.end(),std ::bind2nd(std::mem_fun(&C::IsInteresting),widget)) ;
Not sure what you're trying to accomplish, but this:

std::find_if(m_widgets.begin(),
m_widgets.end(),
std::bind1st(std::mem_fun(&C::IsInteresting),this) );

should at least compile.
}
private:
bool IsInteresting(Widget) {return true;}
list<Widget>m_widgets;
};


V
Jul 22 '05 #4
It doesn't :
error C2784: 'class std::mem_fun_t<_R,_Ty> __cdecl std::mem_fun(_R
(__thiscall _Ty::*)(void))' : could not deduce template argument for
'<Unknown>
' from 'bool (__thiscall C::*)(class Widget)'

Jul 22 '05 #5
Mr X wrote:
It doesn't :
error C2784: 'class std::mem_fun_t<_R,_Ty> __cdecl std::mem_fun(_R
(__thiscall _Ty::*)(void))' : could not deduce template argument for
'<Unknown>
' from 'bool (__thiscall C::*)(class Widget)'


Get a better compiler.
Jul 22 '05 #6
Can someone explain bind2st/bind1st stl functions?
thx

Jul 22 '05 #7
"puzzlecracker" <ir*********@gmail.com> wrote...
Can someone explain bind2st/bind1st stl functions?


What to explain? "Use the Source, Luke!" -- just look at the
'functional' header and find the source for those functions. They
are _literally_ one-liners.

Besides, what book on templates are you reading that doesn't talk
about bind1st/2nd?
Jul 22 '05 #8
dont remember those !

Jul 22 '05 #9

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:KH*******************@newsread1.mlpsca01.us.t o.verio.net...
Mr X wrote:
It doesn't :
error C2784: 'class std::mem_fun_t<_R,_Ty> __cdecl std::mem_fun(_R
(__thiscall _Ty::*)(void))' : could not deduce template argument for
'<Unknown>
' from 'bool (__thiscall C::*)(class Widget)'


Get a better compiler.


Yes. VC++ (at least versions 6.0 and earlier)
is notorious for weak template support.

-Mike
Jul 22 '05 #10

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

Similar topics

5
by: Old Wolf | last post by:
I have a member function that acts on an object. I would also like to have a member function that acts on a container of such objects, using std::for_each. I tried: #include <algorithm>...
2
by: Robbie Hatley | last post by:
I've got a function that I use a lot when making utility programs that need to do the same thing to every directory in a tree. Its prototype is: unsigned long int CursDirs (void Func(void)); ...
13
by: Ioannis Vranos | last post by:
What is the exact difference between mem_fun and mem_fun_ref, since in all examples I looked at, they are used in exactly the same way? -- Ioannis Vranos http://www23.brinkster.com/noicys
4
by: ShaneG | last post by:
We have ptr_fun to handle functions, mem_fun to handle member functions that will be called through a pointer, and mem_fun_ref to handle member functions that will be called through a reference. ...
4
by: david.dfx | last post by:
-------------------------------------------------------------------------------- I'm having a problem implementing the STL map container using a class object. I'd like to use map to store a pair...
8
by: Noah Roberts | last post by:
#include <vector> #include <algorithm> #include <functional> class X { int x; public: X(int i) : x(i) {} bool eq(const X & other) const { return x == other.x; }
1
by: subramanian100in | last post by:
Suppose I have class WordAndLineNumbers { public: void print( ); // other member functions private: // data members
2
by: zelmila19 | last post by:
Hi am working on this program that will display the sum, difference, product and quotient of two numbers using the selection structures. This is what I did: #include <iostream> using...
2
by: Olumide | last post by:
Hello, I've got this nice inner class that I'm holds a set of "FrontPoint" objects as shown below. Unfortunately, the find and insert methods trigger massive C2784 errors. Would someone please...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.