SWIG (Python) - "no constructor defined" for concrete class

Stodge stodge at gmail.com
Fri Apr 18 14:44:43 CEST 2008


Yet another SWIG question (YASQ!).

I'm having a problem with using an abstract base class. When
generating the Python bindings, SWIG thinks that all the concrete
classes that derive from this abstract class are abstract too and
won't create the correct constructor.

Abstract class:

[source lang="cpp"]class CORE_API Shape
{
public:
  virtual ~Shape()
  {
    nshapes--;
  };
  double  x, y;
  virtual void move(double dx, double dy);
  virtual double area(void) = 0;
  virtual double perimeter(void) = 0;
  static  int nshapes;
protected:
  Shape() {
    nshapes++;
  }

};
[/source]

Derived classes:

[source lang="cpp"]class CORE_API Circle : public Shape
{
private:
  double radius;
public:
  Circle(double r): Shape(), radius(r)
  {
  };
  virtual double area(void);
  virtual double perimeter(void);
};

class CORE_API Square : public Shape
{
private:
  double width;
public:
  Square(double r): Shape(), width(r)
  {
  };
  virtual double area(void);
  virtual double perimeter(void);
};
[/source]

SWIG file:

[source lang="cpp"]class Shape
{
  virtual void move(double dx, double dy);
  virtual double area(void) = 0;
  virtual double perimeter(void) = 0;
};

class Circle: public Shape
{
	Circle(double r);
	virtual double area(void);
	virtual double perimeter(void);
};


class Square: public Shape
{
	Square(double r);
	virtual double area(void);
	virtual double perimeter(void);
};
[/source]

C++ COde:

[source lang="cpp"]	Circle c(1.02);
	std::cout << "(c++)\t\tCircle\t" << c.area() << std::endl;
	Square s(9.20);
	std::cout << "(c++)\t\tSquare\t" << s.area() << std::endl;

[/source]

For some reason SWIG thinks that Circle and Square are abstract. Any
ideas why? I'm rather confused by this.

Thanks as always



More information about the Python-list mailing list