next up previous contents index
Next: Point et ColorPoint in Up: Un exemple dans chaque Previous: Un exemple dans chaque

 

Point et ColorPoint in C++ 

#include <stdio.h>

include <fstream.h>

class Point {// interface int x; public: void setx(int y); int getx(); };

//implementation int Point::getx() {return x;}; void Point::setx(int y) {x=y;};

class ColorPoint: public Point {//interface char c; public: void setcol(char d); char *getcol(); };

//implementation void ColorPoint::setcol(char d) {free(c); c=(char )malloc(strlen(d)); strcpy(c,d);}; char *ColorPoint::getcol() {return c;};

main() { Point p; ColorPoint q;

p.setx(3); q.setx(4); q.setcol("blue"); cout<<"Point at " <<p.getx() <<" "<<q.getcol() <<" Colorpoint at " <<q.getx() <<"\n";; }



Roberto DiCosmo
Mon Jun 3 18:29:31 MET DST 1996