Question

I would like to extend the MinimumDiameter class in order to add some more methods. I've tried with the classical C++ syntax:

class ExtendedMinimumDiameter : public MinimumDiameter{};
ExtendedMinimumDiameter *minimumDiameter = new ExtendedMinimumDiameter(inputGeometry);

The problem is that when I try to instantiate an object of my new class, gcc-4.8.2 complains as follows:

operators.cpp:194:92: error: no matching function for call to 'ExtendedMinimumDiameter::ExtendedMinimumDiameter(const geos::geom::Geometry*&)'
         ExtendedMinimumDiameter minimumDiameter = ExtendedMinimumDiameter(inputGeometry);
                                                                                        ^
operators.cpp:194:92: note: candidates are:
operators.cpp:116:7: note: ExtendedMinimumDiameter::ExtendedMinimumDiameter()
 class ExtendedMinimumDiameter : public MinimumDiameter{
       ^
operators.cpp:116:7: note:   candidate expects 0 arguments, 1 provided
operators.cpp:116:7: note: ExtendedMinimumDiameter::ExtendedMinimumDiameter(const ExtendedMinimumDiameter&)
operators.cpp:116:7: note:   no known conversion for argument 1 from 'const geos::geom::Geometry*' to 'const ExtendedMinimumDiameter&'

Why it does not use the parent constructor, and suggests instead to use the default one without parameters? What is missing to my code?

Was it helpful?

Solution

When you create a derivative class, like your ExtendedMinimumDiameter, it's completely new class and you have to create completely new constructors for it. They can be very simple, and just call the parent class constructors (in their initializer lists) and be otherwise empty, but you need to make them yourself.

In this case you have to add e.g.

ExtendedMinimumDiameter(const geos::geom::Geometry* geom)
    : MinimumDiameter(geom)
{}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top