Welcome, Guest. Please login or register.

Author Topic: Storm C++ 3.0 and pointer a function  (Read 8956 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show all replies
Re: Storm C++ 3.0 and pointer a function
« on: January 28, 2003, 11:21:17 AM »
Quote

Darken wrote:
The class function sum is expecting as first argument a pointer to a global function, not a pointer to a class function.

Here is the version of sum() which receives a pointer to a test class function :

class test
{
public:
  double sum( double ([color=FF9900]test::[/color]*g)(int m),int n);
};


Yep!

The thing to remember about function definitions (and hence pointers to functions) is that all non-static class member functions have an invisible argument (the classes' 'this' pointer).

What this means is that

test::sum(double (*g)(int m), int n)

is different from

sum(double (g*)(int m), int n)

and as such have different pointer types.

On the topic of pointers to functions, I'd reccomend that you use a few typedefs to hide the nasty syntax.
int p; // A