Solved

problems using bind2nd

Posted on 2002-05-03
2
264 Views
Last Modified: 2006-11-17
Hi,
I'm using following line in Visual Studio:
for_each(Array.begin(),Array.end(),
bind2nd(mem_fun(&Vertex::Calculate),Radius));

when Array is a std::vector of pointers to Vertex.
class Vertex
{
public:
...
   void Calculate(double Radius);
...
}

But then I get the following error:
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 'void (__thiscall Vertex::*)(double)'

what could be the problem? And how to fix it?
thanks
0
Comment
Question by:borlip
  • 2
2 Comments
 
LVL 3

Accepted Solution

by:
GGRUNDY earned 50 total points
ID: 6989235
Initial comment....
as your member function takes and argument you need to be using mem_fun1.

(I know it doesnt' say this in Bjarne's 3rd edition)
0
 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6989262
and...
I had to make the Calculate function return an integer just to keeps the templates happy :-(

class Vertex
{
public:
...
  int Calculate(double Radius);
...
}

see http://cpptips.hyperformix.com/cpptips/ret_void_ref
for more info. Bjarne is onto it :-)

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question