c++ - Vectors, "virtual", Segmentation Fault on function call -
I am getting a segmentation fault while trying to call a function that is in an object that is "shaped "Pointer"
My problem is in this function:
Point Detection (Point P, Point WakeDear, Int * Status) {Point no PT; For (Int i = 0; I & lt; Shapes.) (I ++) {Point Tapp; Cout & lt; & Lt; "Size shape" & lt; & Lt; Size ..size () & lt; & Lt; Endl; ** SEGMENTATIONFAULT here & gt; & Gt; & Gt; & Gt; ** bull intercept = shapes [0] - & gt; Check Intercense (P, Weekdir, and Temp); If (intersection) {* status = 1; // Code 1 to pierce the actual shape refund temporary; }} Return no PT; }
Initially, I am adding only one size:
zero make ossean () {image = QImage (width, height, 32); // 32 bit field S (dot (0.0.0.0, -50.0), 40.0); Shapes.push_back (& s); Cout & lt; & Lt; Shapes.size () & lt; & Lt; Endl; }
So I have a vector of "figures" which is global. Vector shape;
I have a class shape
#include "point.h" #ifndef SHAPE_H # SHAPE_H using the namespace std; Class shape {public: shape () {} ~ size () {} Virtual Bull Check Interactive (Point P, Point D, Point * Temporary) {}; // If intersects, return true and false truths. Virtual Zero printstoff () {}; }; #endif
and a hemisphere class
#include "shape.h" #include & lt; Math.h> # Include & lt; Algorithm & gt; Using std :: cout; Using the Std :: endl; Using Std :: min; Classroom: Public Size {Public: Point Center Pt; Double radius; Region (Point Center, Double Rod) {centerPt = center; Radius = rad; } Bool checkIntersect (Point P, Point Wake Day, Point * Temp) {cout & lt; & Lt; "Hi" & lt; & Lt; Endl; / * Point _D = p - centerPt; Double A = Point :: Dot (Victor, Weekdir); Double b = 2 * (point :: dot (vecDir, _D)); Double c = (point :: dot (_D, _D)) - (radius * radius); // quadratic equation double tempNum = b * b - 4 * a * c; If (tempNum & lt; 0) {return false; } And {double t1 = (-b + sqrt (tempNum)) / (2 * A); Double T2 = (-b - SQLTemplate) / (2 * A); Double T; If (T1 and LT; 0 & amp; T 2> 0) {T = T2; } And if (t2 and lt; 0 & amp; amp; t1> 0) {t = t1; } And if (t1 and lt; 0 & amp; amp; t 2 and lt; 0) {return false; } And {t = minute (T1, T2); } Point p1 = p + (vecDir * t); If (p1.z> 0) // {return false} on our camera; } And {temp = & amp; P1; Back true; } } */ return false; }};
The problem is here:
area (point (0.0.0.0, -50.0), 40.0); Shapes.push_back (& s);
At this point, you created the area locally on the stack, and you pushed your address into your vector when you leave the scope, then local objects are released. , And so the address you have deposited in your vector is now the memory you remember and its content is undefined.
Instead, do
area = s = new area (dot (0.0.0.0, -50.0), 40.0); Shapes.push_back (s);
To assign an area to the sphere, so that it remains, delete
make sure it is completed when you complete it.
Comments
Post a Comment