1

Error in code in C++ Builder RAD Studio: [bcc32c Error] Unit10.cpp(267): no matching constructor for initialization of 'triangulated_poly'. What's wrong? Please help, so that everything works. //

//---------------------------------------------------------------------------

#include <vcl.h>
#include <vector>
#include <stack>
#pragma hdrstop

#include "Unit10.h"

using namespace std;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm10 *Form10;

int ii=0;
//---------------------------------------------------------------------------
__fastcall TForm10::TForm10(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
class triangulated_poly :public polygone {
    Stack stack;
    int stack_length;
    point left_vertex;
    point right_vertex;
    diagonal* diagonals;
    flag_vertex* x_vertexes;
public:
    triangulated_poly(point* U_points, point* L_points, int UPPER_count, int LOWER_count);
    ~triangulated_poly();

    void x_sort();
    void triangulate();

};


triangulated_poly::triangulated_poly(point* U_points, point* L_points, int UPPER_count, int LOWER_count) :polygone(U_points, L_points, UPPER_count, LOWER_count) {
    ..........
}

triangulated_poly::~triangulated_poly() {
        .......
}



void triangulated_poly::triangulate() {
........
}
//---------------------------------------------------------------------------
void __fastcall TForm10::Button1Click(TObject *Sender)
{
HDC hdc=GetDC(Form10->Handle);
for (int i = 0; i < ii; i++)
{
MoveToEx(hdc,s[i].x,s[i].y,NULL);
LineTo(hdc,s[(i+1)%ii].x,s[(i+1)%ii].y);
}
triangulated_poly poly;
poly.triangulate();
}

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
Allekk
  • 11
  • 1
  • `#pragma hdrstop #include "Unit10.h" using namespace std; //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm"` - I hope to never try to write any cross-platform code, you are going to have some challenges ahead of you.. – Jesper Juhl Dec 22 '19 at 17:46
  • see [Too many initializers error for a simple array in bcc32](https://stackoverflow.com/a/33867999/2521214) that is how my constructors/destructors looks like ... to overcome a nasty BCC32 compiler bug. If you want also operators take a look at this: [GLSL vector math](https://retrocomputing.stackexchange.com/a/6055/6868) Why are you not using VCL's `Canvas->LineTo` and `Canvas->MoveTo` ? no need for GDI/winapi `GetDC` ... VCL do it on its own no need to do it again ... – Spektre Dec 23 '19 at 09:05

1 Answers1

0

The line

triangulated_poly poly;

tries to construct a triangulated_poly using its default constructor.

You never declared a default constructor (i.e. a constructor that excepts an empty argument list) for triangulated_poly and there is no implicitly-declared one because you declared at least one constructor yourself. So the compiler gives you the error that no suitable constructor was found.

Either add a default constructor to triangulated_poly or construct triangulated_poly with an argument list matching triangulated_poly's constructor's parameters:

triangulated_poly poly{/*arguments here*/};
walnut
  • 21,629
  • 4
  • 23
  • 59
  • Thank you. But after adding errors appear: [ilink32 Error] Error: Unresolved external 'polygone::{1173}...' referenced from D:\TRIANGULATEMONOTONEPOLYGON2\WIN32\DEBUG\UNIT10.OBJ [ilink32 Error] Error: Unresolved external 'polygone::{1173}...' referenced from D:\TRIANGULATEMONOTONEPOLYGON2\WIN32\DEBUG\UNIT10.OBJ [ilink32 Error] Error: Unresolved external 'triangulated_poly::triangulated_poly()' referenced from D:\TRIANGULATEMONOTONEPOLYGON2\WIN32\DEBUG\UNIT10.OBJ [ilink32 Error] Error: Unable to perform link – Allekk Dec 22 '19 at 18:01
  • @Allekk Did you also implement the default constructor? Did you compile all source files and link them all together? See [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – walnut Dec 22 '19 at 18:08
  • @Allekk so looks like you are using this in multi form app ... as you got your class in form10 cpp and not in h/hpp instead (or included there as separate file) any time you include form10 header from different window/form you got unresolved external ... try to move your class into separate file and include it in the form h/hpp file instead ... – Spektre Jan 08 '20 at 08:27