HighCommander4
February 5th, 2005, 03:52 PM
I'm getting some weird errors when I'm trying to pass a pointer-to-member-function argument to an STL function like transform(). Here's a simplified version of the code I'm trying to compile:
class myclass
{
private:
vector<int> vec1;
...
int some_function(int x) { return x + 1; }
public:
void member_function()
{
transform(vec1.begin(), vec1.end(), vec1.begin(), some_function);
}
...
};
I am certain that the errors stem from the fact that the last argument to transform() is a pointer to a member function, because if I make some_function a non-member function, the code compiles and works. However, I can't make some_function() a non-member function because I need it to be only accessible from within myclass.
What is the correct way to pass a member function pointer argument to an STL function?
class myclass
{
private:
vector<int> vec1;
...
int some_function(int x) { return x + 1; }
public:
void member_function()
{
transform(vec1.begin(), vec1.end(), vec1.begin(), some_function);
}
...
};
I am certain that the errors stem from the fact that the last argument to transform() is a pointer to a member function, because if I make some_function a non-member function, the code compiles and works. However, I can't make some_function() a non-member function because I need it to be only accessible from within myclass.
What is the correct way to pass a member function pointer argument to an STL function?