Commit 1ca9c605 authored by Danilo Freitas's avatar Danilo Freitas

Test files for cpp classes.

parent 35c00698
cdef extern from "shapes.h" namespace shapes:
cdef cppclass Shape:
area()
cdef cppclass Rectangle(Shape):
int width
int height
__init__(int, int)
cdef cppclass Square(Shape):
int side
__init__(int)
cdef Rectangle *rect = new Rectangle(10, 20)
cdef Square *sqr = new Square(15)
del rect, sqr
#include "shapes.h"
using namespace shapes;
Rectangle::Rectangle(int width, int height)
{
this->width = width;
this->height = height;
}
Square::Square(int side)
{
this->side = side;
}
#ifndef SHAPES_H
#define SHAPES_H
namespace shapes {
class Shape
{
public:
virtual float area() = 0;
virtual ~Shape() { }
};
class Rectangle : public Shape
{
public:
Rectangle(int width, int height);
float area() { return width * height; }
int width;
int height;
};
class Square : public Shape
{
public:
Square(int side);
float area() { return side * side; }
int side;
};
}
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment