[vtkusers] Using vtkSmartPointer with my own classes

John Drescher drescherjm at gmail.com
Wed Dec 22 20:20:41 EST 2010


2010/12/22 Vinicius Rogério Araujo Silva <vinicius.ras at gmail.com>:
> Hello all,
> I've created a simple class, which is a subclass of vtkObject, and tried to
> use vtkSmartPointer with it. The class is as follows:
> class MyClass : public vtkObject
> {
> public:
> MyClass()
> {
> std::cout << "BEING CONSTRUCTED" << std::endl;
> }
> ~MyClass()
> {
> std::cout << "BEING DESTRUCTED" << std::endl;
> }
> };
>

You need to implement the static New function and have your
constructor and destructor protected. Here is the smallest example of
a class that I use vtkSmartPointer with in VS2008.

class smvtkMarkerData : public vtkObject
{
public:
	vtkTypeRevisionMacro(smvtkMarkerData,vtkObject);	
	static smvtkMarkerData*	New();

	typedef vtkSmartPointer< smvtkMarkerData > Ptr;
protected:
	smvtkMarkerData();
	~smvtkMarkerData();

public:
	smPropertyMap*	getSMProps();
	bool			setSMProps(smPropertyMap* pProps);
	bool			isReadOnly();
	void			setReadOnly(bool bReadOnly);
	void			PrintSelf(ostream& os, vtkIndent indent);

private:
	class		smPrivate;
	smPrivate*	m_pPrivate;

private:
	smvtkMarkerData(const smvtkMarkerData&);	// Intentionally Not implemented.
	void operator=(const smvtkMarkerData&);		// Intentionally Not implemented.
};



More information about the vtkusers mailing list