Further cleaning up of class examples
This commit is contained in:
parent
7f40ae3570
commit
0de4cf13a8
29 changed files with 150 additions and 216 deletions
|
|
@ -435,11 +435,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -447,18 +447,18 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -482,19 +482,19 @@ void Shape::move(double dx, double dy) {
|
||||||
|
|
||||||
int Shape::nshapes = 0;
|
int Shape::nshapes = 0;
|
||||||
|
|
||||||
double Circle::area(void) {
|
double Circle::area() {
|
||||||
return M_PI*radius*radius;
|
return M_PI*radius*radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Circle::perimeter(void) {
|
double Circle::perimeter() {
|
||||||
return 2*M_PI*radius;
|
return 2*M_PI*radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Square::area(void) {
|
double Square::area() {
|
||||||
return width*width;
|
return width*width;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Square::perimeter(void) {
|
double Square::perimeter() {
|
||||||
return 4*width;
|
return 4*width;
|
||||||
}
|
}
|
||||||
</pre>
|
</pre>
|
||||||
|
|
|
||||||
|
|
@ -11,18 +11,18 @@ void Shape::move(double dx, double dy) {
|
||||||
|
|
||||||
int Shape::nshapes = 0;
|
int Shape::nshapes = 0;
|
||||||
|
|
||||||
double Circle::area(void) {
|
double Circle::area() {
|
||||||
return M_PI*radius*radius;
|
return M_PI*radius*radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Circle::perimeter(void) {
|
double Circle::perimeter() {
|
||||||
return 2*M_PI*radius;
|
return 2*M_PI*radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Square::area(void) {
|
double Square::area() {
|
||||||
return width*width;
|
return width*width;
|
||||||
}
|
}
|
||||||
|
|
||||||
double Square::perimeter(void) {
|
double Square::perimeter() {
|
||||||
return 4*width;
|
return 4*width;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,16 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
|
|
||||||
enum SomeEnum {
|
enum SomeEnum {
|
||||||
|
|
@ -26,21 +26,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,21 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,16 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,21 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,16 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,21 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,44 +1,34 @@
|
||||||
/* File : example.h */
|
/* File : example.h */
|
||||||
|
|
||||||
class Shape
|
class Shape {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Shape ()
|
Shape() {
|
||||||
{
|
|
||||||
nshapes++;
|
nshapes++;
|
||||||
}
|
}
|
||||||
virtual ~ Shape ()
|
virtual ~Shape() {
|
||||||
{
|
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move (double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area (void) const = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter (void) const = 0;
|
virtual double perimeter() = 0;
|
||||||
protected:
|
static int nshapes;
|
||||||
static int nshapes;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Circle:public Shape
|
class Circle : public Shape {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle (double r):radius (r)
|
Circle(double r) : radius(r) { }
|
||||||
{
|
virtual double area();
|
||||||
};
|
virtual double perimeter();
|
||||||
virtual double area (void) const;
|
|
||||||
virtual double perimeter (void) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square:public Shape
|
class Square : public Shape {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square (double w):width (w)
|
Square(double w) : width(w) { }
|
||||||
{
|
virtual double area();
|
||||||
};
|
virtual double perimeter();
|
||||||
virtual double area (void) const;
|
|
||||||
virtual double perimeter (void) const;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,16 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,28 @@
|
||||||
/* File : example.c */
|
/* File : example.cxx */
|
||||||
|
|
||||||
#include "example.h"
|
#include "example.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define M_PI 3.14159265358979323846
|
#define M_PI 3.14159265358979323846
|
||||||
|
|
||||||
// Static member initializer
|
/* Move the shape to a new location */
|
||||||
int Shape::nshapes = 0;
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Shape::Shape() {
|
|
||||||
nshapes++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move the shape to a new location
|
|
||||||
void Shape::move(double dx, double dy) {
|
void Shape::move(double dx, double dy) {
|
||||||
x += dx;
|
x += dx;
|
||||||
y += dy;
|
y += dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
int Shape::nshapes = 0;
|
||||||
Shape::~Shape() {
|
|
||||||
nshapes--;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Circle area
|
double Circle::area() {
|
||||||
double Circle::area() const {
|
|
||||||
return M_PI*radius*radius;
|
return M_PI*radius*radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Circle perimeter
|
double Circle::perimeter() {
|
||||||
double Circle::perimeter() const {
|
|
||||||
return 2*M_PI*radius;
|
return 2*M_PI*radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Square area
|
double Square::area() {
|
||||||
double Square::area() const {
|
|
||||||
return width*width;
|
return width*width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Square perimeter
|
double Square::perimeter() {
|
||||||
double Square::perimeter() const {
|
|
||||||
return 4*width;
|
return 4*width;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,16 @@
|
||||||
|
|
||||||
class Shape {
|
class Shape {
|
||||||
public:
|
public:
|
||||||
Shape();
|
Shape() {
|
||||||
virtual ~Shape();
|
nshapes++;
|
||||||
|
}
|
||||||
|
virtual ~Shape() {
|
||||||
|
nshapes--;
|
||||||
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area() const = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter() const = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -15,21 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area() const;
|
virtual double area();
|
||||||
virtual double perimeter() const;
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area() const;
|
virtual double area();
|
||||||
virtual double perimeter() const;
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,11 @@ public:
|
||||||
}
|
}
|
||||||
virtual ~Shape() {
|
virtual ~Shape() {
|
||||||
nshapes--;
|
nshapes--;
|
||||||
};
|
}
|
||||||
double x, y;
|
double x, y;
|
||||||
void move(double dx, double dy);
|
void move(double dx, double dy);
|
||||||
virtual double area(void) = 0;
|
virtual double area() = 0;
|
||||||
virtual double perimeter(void) = 0;
|
virtual double perimeter() = 0;
|
||||||
static int nshapes;
|
static int nshapes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -19,21 +19,16 @@ class Circle : public Shape {
|
||||||
private:
|
private:
|
||||||
double radius;
|
double radius;
|
||||||
public:
|
public:
|
||||||
Circle(double r) : radius(r) { };
|
Circle(double r) : radius(r) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
class Square : public Shape {
|
class Square : public Shape {
|
||||||
private:
|
private:
|
||||||
double width;
|
double width;
|
||||||
public:
|
public:
|
||||||
Square(double w) : width(w) { };
|
Square(double w) : width(w) { }
|
||||||
virtual double area(void);
|
virtual double area();
|
||||||
virtual double perimeter(void);
|
virtual double perimeter();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
/* File : example.i */
|
/* File : example.i */
|
||||||
%module example
|
%module example
|
||||||
|
|
||||||
%inline %{
|
%{
|
||||||
#include "example.h"
|
#include "example.h"
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
<H2>Wrapping a simple C++ class</H2>
|
<H2>Wrapping a simple C++ class</H2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
This example illustrates wrapping a simple C++ class to give a Python class.
|
This example illustrates wrapping a simple C++ class to give a Ruby class.
|
||||||
|
|
||||||
<h2>The C++ Code</h2>
|
<h2>The C++ Code</h2>
|
||||||
|
|
||||||
|
|
@ -147,7 +147,7 @@ due to Ruby's sophisticated extension API.
|
||||||
<li>SWIG <b>does</b> know how to properly perform upcasting of objects in
|
<li>SWIG <b>does</b> know how to properly perform upcasting of objects in
|
||||||
an inheritance hierarchy except for multiple inheritance.
|
an inheritance hierarchy except for multiple inheritance.
|
||||||
|
|
||||||
<li>C++ Namespaces - %nspace isn't yet supported for Python.
|
<li>C++ Namespaces - %nspace isn't yet supported for Ruby.
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,3 @@
|
||||||
|
|
||||||
/* Let's just grab the original header file here */
|
/* Let's just grab the original header file here */
|
||||||
%include "example.h"
|
%include "example.h"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -229,11 +229,11 @@ set Shapes_nshapes 13 # Set a static data member
|
||||||
<li>The low-level function interface is much faster than the high-level interface.
|
<li>The low-level function interface is much faster than the high-level interface.
|
||||||
In fact, all the higher level interface does is call functions in the low-level interface.
|
In fact, all the higher level interface does is call functions in the low-level interface.
|
||||||
|
|
||||||
<li>SWIG *does* know how to properly perform upcasting of objects in an inheritance
|
<li>SWIG <b>does</b> know how to properly perform upcasting of objects in an inheritance
|
||||||
hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass
|
hierarchy (including multiple inheritance). Therefore it is perfectly safe to pass
|
||||||
an object of a derived class to any function involving a base class.
|
an object of a derived class to any function involving a base class.
|
||||||
|
|
||||||
<li>C++ Namespaces - %nspace isn't yet supported for Python.
|
<li>C++ Namespaces - %nspace isn't yet supported for Tcl.
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue