Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » method passed as parameter in function
method passed as parameter in function [message #57587] Sun, 03 October 2021 15:04 Go to next message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member
Hi,

These methods below within the class do not allow it to be
compiled this way! is it possible something analogous
so that the fx_ method inside the class
compile on u++? If positive how would it be?

Thanks!


class ab {
public:
	String fx1( Value v1){
		
	 return "fx1";	
	}
	String fx2( Value v2){
		
	 return "fx2";	
	}
	String fx3( Value v3){
		
	 return "fx3";	
	}	
        String fx_( Value v , String (ab::*func)(Value) ){

          return func(v);          
  
        }

};

CONSOLE_APP_MAIN
{
   
   Value v=1;
   ab f
   String x= f.fx_( v, ab::&fx1);
   Cout() << x << EOL;
}


Re: method passed as parameter in function [message #57590 is a reply to message #57587] Mon, 04 October 2021 13:15 Go to previous messageGo to next message
pvictor is currently offline  pvictor
Messages: 67
Registered: December 2015
Member
BetoValle wrote on Sun, 03 October 2021 18:04
Hi,

These methods below within the class do not allow it to be
compiled this way! is it possible something analogous
so that the fx_ method inside the class
compile on u++? If positive how would it be?

Thanks!


class ab {
public:
	String fx1( Value v1){
		
	 return "fx1";	
	}
	String fx2( Value v2){
		
	 return "fx2";	
	}
	String fx3( Value v3){
		
	 return "fx3";	
	}	
        String fx_( Value v , String (ab::*func)(Value) ){

          return func(v);          
  
        }

};

CONSOLE_APP_MAIN
{
   
   Value v=1;
   ab f
   String x= f.fx_( v, ab::&fx1);
   Cout() << x << EOL;
}



Try this:
#include <Core/Core.h>
using namespace Upp;

class ab {
public:
	String fx1( Value v1){
		return "fx1";
	}
	String fx2( Value v2){
		return "fx2";
	}
	String fx3( Value v3){
		return "fx3";
	}
	String fx_( Value v , String (ab::*func)(Value) ){
		return (this->*func)(v);
	}
};

CONSOLE_APP_MAIN
{
   Value v=1;
   ab f;
   String x= f.fx_( v, &ab::fx1);
   Cout() << x << EOL;
}

Re: method passed as parameter in function [message #57593 is a reply to message #57590] Mon, 04 October 2021 13:46 Go to previous message
BetoValle is currently offline  BetoValle
Messages: 203
Registered: September 2020
Location: Brasil Valinhos SP
Experienced Member

now this work fine! Thanks!
Previous Topic: The next step: 32bit wchar
Next Topic: Global Mouse
Goto Forum:
  


Current Time: Sun Jun 16 21:52:32 CEST 2024

Total time taken to generate the page: 0.02199 seconds