[vtkusers] defining a global vtk object
Lubos Brieda
lbrieda at yahoo.com
Tue Jun 5 15:09:26 EDT 2012
I am not familiar with VTK smart pointers, but this seems like a standard C/C++ issue, not a VTK one. A header file gets basically merged into the C file and if you have multiple C files including your header you will end up with multiple instances of the variable. What you want to do instead is define "extern vtkSmartPointer<vtkDoubleArray> X;" in the header file, and then perform the actual allocation in your main(). Also make sure you don't inadvertently end up including the header twice, this is best accomplished by wrapping the entire header by
#ifndef __some_name
#define __some_name
.. your header here ..
#endif
________________________________
From: cel02000 <cel02000 at yahoo.com>
To: vtkusers at vtk.org
Sent: Tuesday, June 5, 2012 3:02 PM
Subject: [vtkusers] defining a global vtk object
Dear All,
How should I define a global vtkDoubleArray? In the header file, I declared:
vtkSmartPointer<vtkDoubleArray> X = vtkDoubleArray::New();
I have a function in mycode.cpp which configures X during run-time. However,
the linker does not like it and give me the following error:
1>main.obj : error LNK2005: "class vtkSmartPointer<class vtkDoubleArray> X"
(?X@@3V?$vtkSmartPointer at VvtkDoubleArray@@@@A) already defined in mycode.obj
Could someone help me?
Thanks,
--
View this message in context: http://vtk.1045678.n5.nabble.com/defining-a-global-vtk-object-tp5713602.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120605/027df682/attachment.htm>
More information about the vtkusers
mailing list