This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Why doesn't it compile? HELP with pointers!


Hi! I am new with cygwin32 but not with gcc.
	When I compile the following code on my linux box with g++, it works
fine. But
it does not with gnu-win32. Can you try to compile it and tell me what
is wrong?

	Many Thanks,
		William Gacquer
___________________________________________________________________

/// @AUTHOR : William Gacquer
//  @DATE : 1997/11/01
//  @TITLE : les pointeurs sur fonctions en C++
//
// De l'art d'utiliser les pointeurs sur des fonctions (membres ou non)
// ce petit exercice peut etre incorpore dans un cours sur le C++.
// il est explicite et permet de decouvrir les trois facons differentes
// de manipuler les pointeurs sur fonctions.
//
// Cet exercice n'utilise pas la STL.

#include <iostream.h>
#include <math.h>
#include <float.h>

class m {
      double c;
      public:
      double wg_mul(double aa, double bb) {
                    c = aa*bb;
                    return c;
      }
      double wg_pow(double aa, double bb) {
                    c = pow(aa,bb);
                    return c;
      }

      double (m::*fcnn)(double aa, double bb);
      void pointe(int n) {
           if (n==1) fcnn = & m::wg_mul;
           if (n==2) fcnn = & m::wg_pow;
      }
      double calcul(double a, double b) {
             c = (fcnn)(a,b);
             return c;
      }
};

double wg_add(double aa, double bb) {
       return (aa+bb);
}

double wg_div(double aa, double bb) {
       return (aa/bb);
}

int main() {
     double a;
     double b;
     a=2.0; b=4.0;
     double c;

     // pointeur classiques sur fonctions non-membres
     double (*fcn)(double aa, double bb);
     fcn=&wg_div;
     c=(*fcn)(a,b);
     cout << c << " = 0.5?" << endl;
     fcn=&wg_add;
     c=(*fcn)(a,b);
     cout << c << " = 6?" << endl;

     // pointeur sur fonction membre par interface (le pointeur fait
partie
     // de la classe)
     m momo;
     momo.pointe(1);
     c=momo.calcul(a,b);
     cout << c << " = 8?" << endl;
     momo.pointe(2);
     c=momo.calcul(a,b);
     cout << c << " = 16?" << endl;

     // pointeur direct sur fonction membre. le pointeur n'est pas
defini
     // dans la classe.
     double (m::*pfd)(double, double);
     pfd = & m::wg_mul;
     c = (momo.*pfd)(a,b);
     cout << c << " = 8?" << endl;
}
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]