Skip to Content.
Sympa Menu

cgal-discuss - RE: [cgal-discuss] Strange problem

Subject: CGAL users discussion list

List archive

RE: [cgal-discuss] Strange problem


Chronological Thread 
  • From: Ben Galehouse <>
  • To:
  • Subject: RE: [cgal-discuss] Strange problem
  • Date: Fri, 25 Jul 2008 09:03:19 -0400

Quoting Xiaofan Li
<>:

As far as I remembered (might be inaccurate), new[] does not initialise all but the first element of the object array. It just allocates the necessary memory space. Try std::vector or std::list instead.

new[] calls the default constructor (and only the default constructor) which should be fine in this case.

The only other quirk of new[] that I can think of is that you are supposed to use delete []. However, if you simply leave it allocated till the end, in something like this, it is normally only valgrind that complains. (Though of course this is a big deal in real code)

Addressing the original poster, there is nothing obviously wrong with the code besides those annoying links and some things that were apparently left out. Adding the delete [] and making changes sufficient to compile, I ended up with the file below, and it seems fine with gcc 4.3 under linux. It is highly likely that you have an overall configuration problem. Do the CGAL examples work? It might be that the more MS focused people here might be able to tell you more if you gave exact compiler version information and the like.

-----------------------

#include <CGAL/basic.h>
#include <CGAL/Point_2.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Polygon_2.h>
typedef CGAL::Cartesian <double > K;
typedef K::Point_2 Point;
typedef CGAL::Polygon_2 <K> Polygon_2 ;
using std::cout;
using std::endl;

int main()
{
Point *points;

points=new Point[ 5 ];

for(int j=0;j<5;j++){

points[j]=Point(2,4);}

delete [] points;
}



Archive powered by MHonArc 2.6.16.

Top of Page