syntax for mem_fun needed

S

subramanian100in

Suppose I have

class WordAndLineNumbers
{
public:
void print( );

// other member functions
private:
// data members
};

vector<WordAndLineNumbers> v;

for_each( v.begin( ), v.end( ), mem_fun(&WordAndLineNumbers::print));

The above usage of mem_fun gives compilation error.

Kindly correct me and give the right syntax for mem_fun.

Thanks
V.Subramanian
 
B

Barry

Suppose I have

class WordAndLineNumbers
{
public:
void print( );

// other member functions
private:
// data members
};

vector<WordAndLineNumbers> v;

for_each( v.begin( ), v.end( ), mem_fun(&WordAndLineNumbers::print));

The above usage of mem_fun gives compilation error.

Kindly correct me and give the right syntax for mem_fun.

The element type of the vector is WordAndLineNumbers, not pointer type,
"mem_fun" is to work with pointer type,
use "mem_fun_ref" instead
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top