W
want.to.be.professer
We know that alomost every algorithm function, such as for_each,
find_if, use funcional as well as function pointer. But when I want
to use another class's member function, how could I do?
See example:
class TestPrint
{
public:
TestPrint( int i ) { start_num = i; }
void print( int i )
{
cout << endl<< "| " << i + start_num <<
" |" << endl;
}
private:
int start_num;
};
int main()
{
TestPrint* pTest = new TestPrint( 8 );
int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for_each( a, a + 9, /*** Use the pTest's "print" ***/ );
delete pTest;
return 0;
}
/*** Use the pTest's "print" ***/ is where I want to write code .
find_if, use funcional as well as function pointer. But when I want
to use another class's member function, how could I do?
See example:
class TestPrint
{
public:
TestPrint( int i ) { start_num = i; }
void print( int i )
{
cout << endl<< "| " << i + start_num <<
" |" << endl;
}
private:
int start_num;
};
int main()
{
TestPrint* pTest = new TestPrint( 8 );
int a[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
for_each( a, a + 9, /*** Use the pTest's "print" ***/ );
delete pTest;
return 0;
}
/*** Use the pTest's "print" ***/ is where I want to write code .