Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2693 connectés 

  FORUM HardWare.fr
  Programmation
  C++

  from c function func(double (*g(char*))) to cpp cool object design

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

from c function func(double (*g(char*))) to cpp cool object design

n°1781736
mp3butcher
Posté le 03-09-2008 à 09:43:29  profilanswer
 

Hello,
I want to convert a c function  
 
void func(double (*g(char*))) ;
 
to a cpp object where we could specifie the function pointer per object instance.
I try functor ,member function pointer but the only paramater this function like to have is a static member function:(
Can someone help me deal with this problem?

mood
Publicité
Posté le 03-09-2008 à 09:43:29  profilanswer
 

n°1781818
Amonchakai
Posté le 03-09-2008 à 11:02:16  profilanswer
 

Hello,  
 
   I think that boost::function can help you.

n°1781848
Joel F
Real men use unique_ptr
Posté le 03-09-2008 à 11:39:02  profilanswer
 

a member function is different from a function.
For a given object A, the type of int A::f(int) is in fact :
 
int (A::*)(int);
or int (*)(A*,int);
 
use boost::function as stated.

n°1781850
mp3butcher
Posté le 03-09-2008 à 11:42:19  profilanswer
 

I would like not to add external dependencies to my project...There's no other solution:/?  
It seems to be a quite complex to solve the problem no?

n°1781887
Joel F
Real men use unique_ptr
Posté le 03-09-2008 à 12:10:50  profilanswer
 

well, the dichotomy between function function member IS a hard problem. Boost solves it properly in allc ases of compiler/platform/type of function.
 
By dependencies, you mean at runtime ? If so, don't fear, boost is mostly headers only. If you want to minimize the boost packages needed for compilation , look at boost::BCP

n°1781959
mp3butcher
Posté le 03-09-2008 à 13:39:40  profilanswer
 

Ok, I've test a few things, but my c function don't want a boost::function as argument, it's incompatible. So can you explain moreover what you think?

n°1782104
Joel F
Real men use unique_ptr
Posté le 03-09-2008 à 15:41:37  profilanswer
 

I was thinking the other way around.
You can't pass a C++ object to a C function anyway.
 
Best shot is making a class with a static method which encapsulates the actual method member into a boost::function.

n°1782474
mp3butcher
Posté le 04-09-2008 à 11:26:45  profilanswer
 

class CPP{
 
   static void CPPFunc(function1<double,char*> f){
           double (*fprim)(char*)=f;
           cfunc(fprim);
}
};
?????????
no I dont understand...:((
 

n°1782579
mp3butcher
Posté le 04-09-2008 à 14:32:15  profilanswer
 

or  
 
class CPP{
private:
function2<double,CPP*,char*>* g;
public:
static double gcall(char*c){
return g(c);
}
virtual double gimpl(char*){blabla}
void exec(){
     g=new function2<double,CPP*,char*>(bind(CPP::gimpl,this,_1));
     cfunc(gcall);
}
Is it more like you're thinking?
No there's always a problem...arg


Message édité par mp3butcher le 04-09-2008 à 14:41:36
n°1782789
Taz
bisounours-codeur
Posté le 04-09-2008 à 19:58:26  profilanswer
 

WTF

mood
Publicité
Posté le 04-09-2008 à 19:58:26  profilanswer
 

n°1782945
mp3butcher
Posté le 05-09-2008 à 10:10:00  profilanswer
 

Excuse me I don't know what to do with function<> for my problem...:(


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C++

  from c function func(double (*g(char*))) to cpp cool object design

 

Sujets relatifs
T_OBJECT_OPERATORRenseigner le champ From d'Outlook avec Excel
Iframe >< objectDouble socket
[Résolu] static function : normalement pas appelables avec ->passing argument 1 of «NomFonction» from incompatible pointer type
[Réglé][JavaScript] Erreur 'Object expected'[ACCESS] Procédure double clic sur enregistrement
design patern et livres c++ 
Plus de sujets relatifs à : from c function func(double (*g(char*))) to cpp cool object design


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR