[vtkusers] "vtkProp* const GetProp()" != "const vtkProp* GetProp()" ??

Peter F Bradshaw pfb at exadios.com
Wed Dec 14 01:51:52 EST 2005


Hi Jens;

On Tue, 13 Dec 2005, Jens wrote:

> Hi
> I wonder if there is any difference between
> 	1.	vtkProp* const vtkAssemblyNode::GetProp()
> and
> 	2.	const vtkProp* vtkAssemblyNode::GetProp()
>
> Version 1 is part of VTK-5 but I havn´t seen such C++ code, yet.
> For wrapping vtk I need to know if I can change it to Version 2 ?

'type *const' and 'const type *' are not the same thing at all. The
first is a "promise" not to change the value of the pointer and the
second is a promise not to change the object pointed to.

In the first case we could have the following:

  vtkProp *const prop = AssemblyNodeObject->GetProp();
  prop->VisibilityOn();                  // Call this, or any other,
                                         // vtkProp member.
  prop = AssemblyNodeObject->GetProp();  // Error - cannot assign to
                                         // read only var "prop" and,
                                         // thereby, break a promise
                                         // of the first type.

But, in the second case:

  const vtkProp *prop = AssemblyNodeObject->GetProp();
  prop->VisibilityOn();                  // Error - VisibilityOn() is
                                         // not declared 'const' and
                                         // may change the object
                                         // pointed to by prop and,
                                         // therefore, break a promise
                                         // of the second type.
  prop = AssemblyNodeObject->GetProp();  // This would work ok.

However, the following should work (and possibly solve your problem):

  vtkProp *prop = AssemblyNodeObject->GetProp();
  prop->VisibilityOn();                  // Ok - no const vtkProp *
  prop = AssemblyNodeObject->GetProp();  // Ok - no vtkProp const *

>
> Any C++ guru out there?
>
> 	Greetings
> 		Jens

Cheers

-- 
Peter F Bradshaw, http://www.exadios.com, ICQ 75431157 (exadios).
Public key at www.exadios.com/pfb.pgp.key and www.exadios.com/pfb.gpg.key
"I love truth, and the way the government still uses it occasionally to
 keep us guessing." - Sam Kekovich.



More information about the vtkusers mailing list