Next: Mise en uvre Up: Mise en uvre Previous: Mise en uvre

Rappels polymorphisme


#include <iostream.h>

class Object {
public:
  void affiche(const char *msg) const ;
} ;

void Object::affiche(const char *msg) const {
 cout << msg << endl ; 
}

typedef Object *PtrObject ;

void fonc1(const PtrObject &po) {
  po->affiche("fonc1:hello...") ;
}

void fonc2(const Object &po) {
  po.affiche("fonc2:hello...") ;
}

class SousObject : public Object {
} ;

int main(void) {
  PtrObject p = new SousObject() ;
  SousObject so ;
  fonc2(so) ;
  fonc1(p) ;
  return 0 ;
}

@
vendredi, 7 novembre 1997, 14:51:48 MET