[vtkusers] Small API change to vtkIndent

Berk Geveci berk.geveci at kitware.com
Mon Feb 11 11:47:09 EST 2008


Hi folks,

I would like to make a small change to vtkIndent that has a slight
backward compatibility problem. Here is the change I am suggesting:

33c33
<   vtkIndent(int ind=0) {this->Indent=ind;};
---
>   explicit vtkIndent(int ind=0) {this->Indent=ind;};

This is to remove implicit conversion of integers to vtkIndent objects
in order to avoid subtle bugs (more on this below).  With this change,
you will have to change something like:

foo->Print(std::cout, 0);

to

foo->Print(std::cout, vtkIndent(0));

Explanation:

First: VTK forward declares iostream operators. Unless you include the
right header files, you do not get any << or >> defined for even basic
types, including integers.

Second: VTK defines a << operator for vtkIndent.

As a result, unless you include the right include files

ofstream foo;
foo << 2;

would compile as

ofstream foo;
foo << vtkIndent(2);

This is probably not what most people intend to do. Adding the
explicit keyword will fix this issue. Unless anybody objects to this
strongly, I will commit this change in a day or so.

Cheers,
-berk



More information about the vtkusers mailing list