[vtkusers] implementing New() in vtk subclasses..

Miller, James V (CRD) millerjv at crd.ge.com
Mon Jul 2 17:30:24 EDT 2001


The string you pass to the factory should match the name of the class.

Constructors (default and copy constructor) the destructor and operator= for class should be made
protected.  As such they are protected from being called by the programmer.

All instances should created using the New() method, i.e.

vtkSomeObject *myInstance = vtkSomeObject::New();

This call to New() will trigger your classes constructor and hence the constructors of all its
superclasses.

When you are done with your instance call

myInstance->Delete();

to remove your reference handle to the object.  This may not actually delete the object due to
reference counting if another vtk object has a handle to it.

Jim


-----Original Message-----
From: K. R. Subramanian [mailto:krs at cs.uncc.edu]
Sent: Sunday, July 01, 2001 6:58 PM
To: VTK HELP
Subject: [vtkusers] implementing New() in vtk subclasses..



A simple question.. I am subclassing a  vtk classes, and I would like
to write a constructor, similar to New(). I notice New() creates
instances from an
object factory (which I must confess I know very little about!).  In any
case, the instance
call takes a string argument - is this part of  a library of names used
within VTK, or is this
something the user supplies to id the object?

In any case, in subclasses, what is the preferred method to create
objects?  Right now,
I am just using the C++ new operator, which I believe  is not
recommended for creating vtk objects..
I know you can call the superclass's (which is the vtk object) New()
constructorwithin the
constructor of the subclass, but what do I do with the return value?

Thanks.

    -- krs

--
Dr. K.R.Subramanian                           Phone: (301) 402-0042
National Institutes of Health                 FAX:   (301) 402-4080
National Library of Medicine                  Email: krs at cs.uncc.edu
Bldg 38A, Rm. B1N30D                          WWW: www.cs.uncc.edu/~krs
8600 Rockville Pike, Bethesda, MD 20894




_______________________________________________
This is the private VTK discussion list. 
Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers




More information about the vtkusers mailing list