New example for templates
This commit is contained in:
parent
0390648862
commit
0ac03d9fe9
5 changed files with 142 additions and 0 deletions
36
Examples/scilab/template/example.h
Normal file
36
Examples/scilab/template/example.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* File : example.h */
|
||||
|
||||
template<typename T>
|
||||
class Shape {
|
||||
private:
|
||||
static int nbshapes;
|
||||
public:
|
||||
Shape() { x = 0; y = 0; nbshapes++; }
|
||||
virtual ~Shape() { nbshapes--; };
|
||||
T x, y;
|
||||
void move(T dx, T dy);
|
||||
virtual T area() = 0;
|
||||
virtual T perimeter() = 0;
|
||||
static int getNbShapes();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Circle : public Shape<T> {
|
||||
private:
|
||||
T radius;
|
||||
public:
|
||||
Circle(T r) : Shape<T>() { radius = r; };
|
||||
virtual T area();
|
||||
virtual T perimeter();
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Square : public Shape<T> {
|
||||
private:
|
||||
T width;
|
||||
public:
|
||||
Square(T w) : Shape<T>() { width = w; };
|
||||
virtual T area();
|
||||
virtual T perimeter();
|
||||
};
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue