error: must use '.*' or '->*' to call pointer-to-member function in '__unary_op (...)'

E

er

hi!

a little compiler error. pls help.

class A{
B get(unsigned int i);// return an B object whose state depend on
*this and i
std::vector<B> get_vec(){
std::vector<unsigned int> ints(n);
iota(ints.begin(),ints.end(),0);
std::vector<B> ret;
transform(
ints.begin(),
ints.end(),
back_inserter(ret),
get//or &get, *this.*get etc...
);
return ret;
};
private:
unsigned int n;
}


In function '_OutputIterator std::transform(_InputIterator,
_InputIterator, _OutputIterator, _UnaryOperation) [with _InputIterator
= __gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned
int, std::allocator<unsigned int> > >, _OutputIterator =
std::back_insert_iterator<std::vector<B, std::allocator<B> > >,
_UnaryOperation = B (A::*)(unsigned int)]':
.../A.cpp:40: instantiated from here
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
stl_algo.h:925: error: must use '.*' or '->*' to call pointer-to-
member function in '__unary_op (...)'
 
E

er

hi!

a little compiler error. pls help.

class A{
B get(unsigned int i);// return an B object whose state depend on
*this and i
std::vector<B> get_vec(){
std::vector<unsigned int> ints(n);
iota(ints.begin(),ints.end(),0);
std::vector<B> ret;
transform(
ints.begin(),
ints.end(),
back_inserter(ret),
get//or &get, *this.*get etc...
);
return ret;
};
private:
unsigned int n;

}

In function '_OutputIterator std::transform(_InputIterator,
_InputIterator, _OutputIterator, _UnaryOperation) [with _InputIterator
= __gnu_cxx::__normal_iterator<unsigned int*, std::vector<unsigned
int, std::allocator<unsigned int> > >, _OutputIterator =
std::back_insert_iterator<std::vector<B, std::allocator<B> > >,
_UnaryOperation = B (A::*)(unsigned int)]':
../A.cpp:40: instantiated from here
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/../../../../include/c++/4.1.2/bits/
stl_algo.h:925: error: must use '.*' or '->*' to call pointer-to-
member function in '__unary_op (...)'

small correction: class A{ public: /*same*/
 
B

Barry

er said:
hi!

a little compiler error. pls help.

class A{
public:

B get(unsigned int i);// return an B object whose state depend on
*this and i
std::vector<B> get_vec(){
std::vector<unsigned int> ints(n);
iota(ints.begin(),ints.end(),0);
std::vector<B> ret;
transform(
ints.begin(),
ints.end(),
back_inserter(ret),
get//or &get, *this.*get etc...

bind1st(mem_fun(&A::get), this)
 
E

er


i have a similar question but this time the member function is the
constructor (static?)

class A{
public:
A(unsigned int,unsigned int);
}

my goal is to generate std::vector<A(0,n),...,A(N-1,n)>

unsigned int n,N;
std::vector<A> ret;
transform(
boost::counting_iterator<int>(0),
boost::counting_iterator<int>(N),
back_inserter(ret),
/* what should i put here?*/
);
 
B

Barry

er said:
i have a similar question but this time the member function is the
constructor (static?)

class A{
public:
A(unsigned int,unsigned int);
}

my goal is to generate std::vector<A(0,n),...,A(N-1,n)>

unsigned int n,N;
std::vector<A> ret;
transform(
boost::counting_iterator<int>(0),
boost::counting_iterator<int>(N),
back_inserter(ret),
/* what should i put here?*/

boost::lambda::bind(boost::lambda::constructor<A>(), _1, _2)

Be aware: I didn't compile this code

As &A::A is illformed.
Use a wrapper, a free function

A CreateA(unsigned int i, unsigned int j)
{
return A(i, j);
}

or functor(mentioned above).
You can refer to
Boost.Lambda constructor
 
E

er

sorry, after second thought
no need to bind, just

boost::lambda::constructor<A>()

thanks,

transform(
boost::counting_iterator<int>(0),
boost::counting_iterator<int>(N),
back_inserter(ret),
boost::lambda::bind(
boost::lambda::constructor<A>(),
boost::lambda::_1,
n
)
);
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top