[vtkusers] Access violation when using vtkPolyDataReader

tom fogal tfogal at apollo.sr.unh.edu
Fri Jul 29 11:30:56 EDT 2005

 <42E947AC.3080209 at nmr.mgh.harvard.edu>Sean McInerney writes:
>3. Why not use C++'s operator new? It throws an exception and aborts by
>default if an allocation fails.

good call.

>David Cole wrote:
>>> assert(readers=(vtkPolyDataReader**)calloc(inputs,sizeof(vtkPolyDataReader*

You cannot use C memory allocation routines to get memory for C++
objects. If you want an array of vtkPolyDataReaders, you want to do
something like this:

readers = new vtkPolyDataReader[number_of_elements_in_array];

I'm not sure VTK's allocation model (via ::New()) allows this. You
could probably declare the 'readers' variable as an array in the
function, and then allocate. For example:

void somefunc() {
	int i;
	vtkPolyDataReaders *readers[10];

	for(i=0; i < 10; ++i) { readers[i] = vtkPolyDataReader::New(); }



More information about the vtkusers mailing list