- Don't be afraid to use public data members. For something like a Point struct, there's nothing wrong with having x, and w publically accessible. One of the false assumptions about OOP is that all members need to be protected/private -- having set/get member functions for something like that is a little silly.
- Logically, it would make sense for your polygon to generate and maintain its own points, rather than you supplying the polygon with points to use. After all the points are part of the polygon, and therefore it makes more logical sense to make the points part of the polygon class. This will make your class easier to use and will reduce the occurance of bugs.
- this is your segfault problem:
1 2
|
ctrlPolygon1D *poly; // <--- this creates a POINTER, not an object. the pointer points to nothing
poly -> Pw = Pw; // <--- trying to derefence a pointer that points to nothing = segfault
|
A solution is to not use a pointer, but to just make an object directly:
1 2
|
ctrlPolygon1D poly;
poly.Pw = Pw;
|
Or dynamically allocate the polygon:
1 2 3
|
ctrlPolygon1D* poly;
poly = new ctrlPolygon1D; // make it actually point to something
poly->Pw = Pw; // no more segfault
|
- You have memory leaks! Whenever you call new, there must be a corresponding call to delete. And for new[], you must use delete[]. You're never delete[]'ing your 'Pw' and 'U' arrays.
EDIT -- blah. I'm too slow