cycovery
Erfahrenes Mitglied
Hi!
habe zwei probleme mit struct constructoren.
hier mein struct im header (was da genau gerechnet wird ist eigentlich egal):
Frage 1:
Wie krieg ich die implementation der konstruktoren ins cpp file? ist irgendwie hässlich, wenn das im header steht.
Frage2:
Nachdem ich die konstruktoren ins struct eingefügt habe krieg ich bei folgender funktion auf linie "MyLine* CTool...." den compilerror: Error 22 error C4430: missing type specifier - int assumed. Note: C++ does not support default-in
was geht da schief?
Ja ich weiss - wenn ich ne klasse statt nem struct verwenden würde hätte ich diese Probleme wohl nicht - aber ich würde es trotzdem gerne wissen.
Dankeschön![Smile :) :)](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f642.png)
habe zwei probleme mit struct constructoren.
hier mein struct im header (was da genau gerechnet wird ist eigentlich egal):
Code:
struct MyLine{
CvPoint pt1,pt2,directionpoint; //pt1 and pt2 points on the line, directionpoint: a point on a circle that represents the lines orientation (used for clustering)
float rho, theta; //rho distance to zero and theta angle of the line
int cluster; //to which cluster does the line belong
MyLine(){};
MyLine(float rho, float theta): rho(rho), theta(theta), cluster(0){
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
};
MyLine(CvPoint pt1, CvPoint pt2): pt1(pt1), pt2(pt2), cluster(0){
double dirX = pt2.x-pt1.x, dirY=pt2.y-pt1.y;
float tmptheta = atan2(dirX,dirY)-M_PI_2;
double a = cos(tmptheta), b = sin(tmptheta);
double tmpx = a*2000, tmpy = b*2000;
CvPoint zero,tmppt;
tmppt.x=tmpx;tmppt.y=tmpy;
MyLine tmpline1 = MyLine(zero,tmppt);
MyLine tmpline2;
tmpline2.pt1=pt1;tmpline2.pt2=pt2;
CvPoint2D32f linepoint = Intersection(tmpline1,tmpline2);
rho = sqrt(linepoint.x*linepoint.x+linepoint.y*linepoint.y);
theta = atan2(linepoint.x,linepoint.y);
};
MyLine(CvPoint pt1, float theta): pt1(pt1), theta(theta), cluster(0){
double a = cos(theta), b = sin(theta);
pt2.x = pt1.x+a*2000; pt2.y = pt1.y*2000;
a = cos(theta-M_PI_2), b = sin(theta-M_PI_2);
double tmpx = a*2000, tmpy = b*2000;
CvPoint zero,tmppt;
tmppt.x=tmpx;tmppt.y=tmpy;
MyLine tmpline1 = MyLine(zero,tmppt);
MyLine tmpline2;
tmpline2.pt1 = pt1, tmpline2.pt2=pt2;
CvPoint2D32f linepoint = Intersection(tmpline1,tmpline2);
rho = sqrt(linepoint.x*linepoint.x+linepoint.y*linepoint.y);
};
};
Frage 1:
Wie krieg ich die implementation der konstruktoren ins cpp file? ist irgendwie hässlich, wenn das im header steht.
Frage2:
Nachdem ich die konstruktoren ins struct eingefügt habe krieg ich bei folgender funktion auf linie "MyLine* CTool...." den compilerror: Error 22 error C4430: missing type specifier - int assumed. Note: C++ does not support default-in
Code:
MyLine* CToolDePerspective::FindLines(IplImage* input )
{
...
MyLine* linien = (MyLine *) malloc (sizeof(MyLine)*line_count);
...
return linien;
}
was geht da schief?
Ja ich weiss - wenn ich ne klasse statt nem struct verwenden würde hätte ich diese Probleme wohl nicht - aber ich würde es trotzdem gerne wissen.
Dankeschön
![Smile :) :)](https://cdn.jsdelivr.net/joypixels/assets/8.0/png/unicode/64/1f642.png)