| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 
 | #include <iostream>
 
class SimpleClass {
  float x0_;
  public :
   SimpleClass();
   virtual ~SimpleClass(){};
   float f(float x){return x+x0_;};
   float F(float (*func)(float), float a, float b);
};
 
float g(float x){return x+1;};
 
SimpleClass::SimpleClass() : x0_(1) {
  float (*func) (float);
  //func = f;// ne compile pas
  func = g; // compile et fonctionne correctement
  std::cout<<F(func,2,4)<<"\n";
}
 
float SimpleClass::F(float (*func)(float), float a, float b){
  return (*func)(a)+(*func)(b);
}
 
int main (){
 SimpleClass ab;
 return 0;
} | 
Partager