|
-
February 5th, 2005, 04:52 PM
#1
How to manage member function pointers correctly?
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:
Code:
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?
Old Unix programmers never die, they just mv to /dev/null
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|