954,498 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to call an outside function inside a class which has a class parameter?

I have a function which acts on class member function:

template <typename ClassType>
double Integral(ClassType& obj, double (ClassType::*func)(double), double lower_limit, double upper_limit)
{...}


This can be call like this from outsie:

class myclass{
public:
double classfunction(double);
};

double myclass::classfunction(double x) {...}

int main()
{
myclass probe;
std::cout << Integral(probe, &myclass::classfunction);
}


But how can I call this Integral function inside the class, from a member function?
I guess I have to use "this" but it doesnt work:

class myclass{
public:
  double classfunction(doube);
  double classint(double a, double b) 
    { 
      return Integral(this, &myclass::classint, a, b); 
    } 
};
merse
Junior Poster
155 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

I've found the answer to my question (replace "this" by "*this")
but I have another:
what if the classfunction is private in the example?
inside the class I can acces to it,
but how can I pass to the outside Integrand function?

merse
Junior Poster
155 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You