user1195321
user1195321

Reputation: 105

C++ Static member pointer to function - how to initialize it?

I have a static pointer to function like the following in my class, but I'm not sure how to instantiate it:

class Foo{ 
 private:   
    static double (*my_ptr_fun)(double,double);                               
};

Upvotes: 9

Views: 5318

Answers (1)

pmr
pmr

Reputation: 59811

The same way you would initialize every other static member object in C++03:

class Foo{ 
 private:   
    static double (*my_ptr_fun)(double,double);                               
};

double bar(double, double);

double (*Foo::my_ptr_fun)(double,double) = &bar;

Whatever you would need a static function pointer for anyway.

This is called initialization. instantiation means something different in C++.

Upvotes: 11

Related Questions