Subject: CGAL users discussion list
List archive
- From: "John Yamokoski" <>
- To:
- Subject: problems with custom point class...
- Date: Thu, 5 Jul 2007 10:47:59 -0400
Greetings,
I have been having some trouble with my own custom point class and the spatial search library in CGAL. Using example 45.3.5 as a guide I have created my own point class. The difference between mine and the one listed in the example is that I am dynamically allocating storage for the point data when the point object is created by using the new operator. However, I get a failed assertion during runtime after I insert one of my points into a tree. Below is the section of code where my program fails as well as the definition of my point class. Does this have something to do with me dynamically allocating storage inside the point class?
// Offensive code snippet:
// Variables declared elsewhere:
// double* ptr - points to flattened array of my point data
// int nDim - number of dimensions for the point data
// int nSamples - number of points that I am going to be adding to the tree
for (int n=0; n < nSamples; ++n) {
Point p(nDim, ptr + (n * nDim))
g_Tree->insert( p );
} // <--- Program asserts failure right here... seems to be when the Point object goes out of scope and gets destroyed?
// Declared in point.h, my point class
struct Point
{
Point(unsigned int n, const double* ptr) : N(n)
{
data = "new" double[N];
for (unsigned int ii=0; ii < N; ++ii) data[ii] = ptr[ii];
}
~Point() {if (data) delete [] data;}
bool operator==(const Point& p) const
{
for (unsigned int ii=0; ii < N; ++ii) {
if (data[ii] != p.data[ii]) return false;
}
return true;
}
bool operator!=(const Point& p) const
{
return !(*this == p);
}
double *data;
unsigned int N;
};
- problems with custom point class..., John Yamokoski, 07/05/2007
- Re: [cgal-discuss] problems with custom point class..., Camille . Wormser, 07/08/2007
- Message not available
- Re: [cgal-discuss] problems with custom point class..., John Yamokoski, 07/09/2007
- Message not available
- Re: [cgal-discuss] problems with custom point class..., Camille . Wormser, 07/08/2007
Archive powered by MHonArc 2.6.16.