Questions tagged [mem-fun]

29 questions
1
vote
2 answers

Member Variable Pointer

For a given struct: struct foo { void fooFunc(){} int fooVar = 0; }; I can create a call wapper to the function: std::mem_fn( &foo::fooFunc ) such that I can pass it into another method and call it on an object. I want to know if there is a…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
1
vote
1 answer

why the member function mem_fun calls must be a const one?

mem_fun and mem_fun_ref and many other member function adaptors can make member functions act like orindinary functions. But there is one restriction that the member function that they call must be a const one. I get to know how to use them, but…
richard.g
  • 3,585
  • 4
  • 16
  • 26
1
vote
1 answer

Deficiency in std::mem_fn compared to hand-rolled functor

I have come across a use case where std::mem_fn cannot do something that a hand-rolled wrapper function can. It comes up when the wrapper function is used on something that's not of the method's class, but a type implicitly convertible to…
HighCommander4
  • 50,428
  • 24
  • 122
  • 194
1
vote
1 answer

Set labels of multiple wxTextCtrls to empty values using foreach

I've been trying to set multiple labels of wxTextCtrl to empty values using for_each like this: std::deque dqImg; for_each (dqImg.begin(),dqImg.end(),bind1st(mem_fun(&wxTextCtrl::SetLabel),"")); the problem is it gives me this…
DropDropped
  • 1,253
  • 1
  • 22
  • 50
0
votes
4 answers

Calling a member function with one parameter (bound) for each object in a container

I have a using namespace std; typedef vector CoilVec; CoilVec Coils; with Coil being a base class for CilCoil and RectCoil, a cilindrical coil and a rectangular coil, respectively. Now I wish to invoke a member function calcField on each…
Wouter
  • 161
  • 1
  • 6
0
votes
2 answers

std::mem_fun_ref problem: Works as functor broken when called as a member function

The problem is compiler errors with the code snippet below. Here's a very simple program to fill a list with random integers and increment each element. I use a std::for_each call to a functor to increment each member of my collection and all…
0
votes
2 answers

Why Can't I use a mem_fn Functor in bind?

I wanted to pass a mem_fn argument to bind but the compiler doesn't seem to allow it. For example this works fine: accumulate(cbegin(foos), cend(foos), 0, bind(plus(), placeholders::_1, bind(&foo::r, placeholders::_2))); But when I try to use…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
0
votes
1 answer

Array of function pointers ( including member functions) throwing template specialization error

So, I have a class called Delegate that can store an array of function pointers. This is the code: template class delegate { private: public: typename std::vector mListOfFunctions; void Bind(Func f) { …
Ashwin Narayanan
  • 123
  • 1
  • 1
  • 6
0
votes
2 answers

C# equivalent of C++ mem_fun?

I'd like to do something like the following in C#: class Container { //... public void ForEach(Action method) { foreach (MyClass myObj in sequence) myObj.method(); } } //... …
Martin Stone
  • 12,682
  • 2
  • 39
  • 53
0
votes
2 answers

gtkmm compiler error when connecting signal

I'm working on an application with a GUI and I'm having trouble when trying to emit a signal (sig_showList, from View) at the connect for another signal (signal_changed, from Gtk::ComboBox), I'd really appreciate your help. The code looks something…
Chrischpo
  • 145
  • 1
  • 11
0
votes
2 answers

find inside a class if an element exists within a vector of pairs

I'm coding in C++. I have a project with so many files. I have a vector of pairs named list as follows: std::vector< std::pair< structure1, double> > list; and I want to check if for a specific double value z , there exists an element: el in the…
Saddam
  • 25
  • 8
0
votes
0 answers

Call a std::function class member with std::mem_fn

My plan is to build several listener classes which own predefined "callback hooks". In the example below class Foo has a "callback hook" called onChange. It will be set to a default callback function during construction. It can also be set to an…
iam_peter
  • 3,205
  • 1
  • 19
  • 31
0
votes
2 answers

How can I solve this ambiguousity wrt. mem_fun?

To practice, one of the topics I'm familiarizing myself with again is trees. The thing about depth-first search and breadth-first search is that they differ only in the choice of the data structure that backs the algorithm. I thought I could write a…
primfaktor
  • 2,831
  • 25
  • 34
-1
votes
4 answers

std::transform with virtual call operator throws "global functions do not have 'this' pointers"

PayOff is an abstract base class and CallPayOff and PutPayOff derive from it. The call operator is defined as a pure virtual function in base class and CallPayOff and PutPayoff provide their own implementations. vector v; v.push_back(new…
user2696565
  • 587
  • 1
  • 8
  • 17
1
2