[Fwd: How to take the member function as the function argument?]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



OK I have solved the problem:

#include<iostream>
#include<complex>

using namespace std;

//#include"/home/benjamin/diplomaProg/headers/ComplexUnit.h"
//#include"/home/benjamin/diplomaProg/headers/Derivator.h"

class Uporaba
{
	private:
		double sestej(double a,double b){
			return a+b;
		}
		
		double naredi(double (Uporaba::*F)(double,double),double a, double b){
			double c;
			c = (this->*F)(a,b);
			return c;
		}
		
	public:		
		
		Uporaba(){}			
		
		double rezultat(double a,double b){
			
			return naredi(&Uporaba::sestej,a,b);
		}
	
};

int main(){
	
	Uporaba inst = Uporaba();
	cout << inst.rezultat(1,2) << endl;
	
	return 0;
}

But is this the most elegant way?
--- Begin Message ---
I have a simple test program:

#include<iostream>

using namespace std;

class Uporaba
{
	private:
		double sestej(double a,double b){
			return a+b;
		}
		
		double naredi(double (Uporaba::*F)(double,double),double a, double b){
			double c;
			c = (this->*F)(a,b);
			return c;
		}
		
	public:		
		
		Uporaba(){}
		
		double rezultat(double a,double b){
			
			return naredi(sestej,a,b);
		}
	
};

int main(){
	
	Uporaba inst = Uporaba();
	cout << inst.rezultat(1,2) << endl;
	
	return 0;
}

Compiler gives an error:

error: no matching function for call to 'Uporaba::naredi(<unknown
type>,double&,double&)'

What is wrong? Please help.

Benjamin

--- End Message ---

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux