[vtk-developers] Unique PIMPL class names
Bill Hoffman
bill.hoffman at kitware.com
Thu Jan 9 16:22:18 EST 2003
Nested classes are not supported by all compilers.
Specifically, you can not forward declare a nested class,
and put the implementation in a .cxx file which is what we need
for "Pimpl". Due to some dashboard errors, we recently had
to change some code like this:
---vtkFoo.h----
class vtkFoo
{
private:
class vtkBar; // forward declare nested class
vtkBar* Bar;
};
----vtkFoo.cxx-----
class vtkFoo::vtkBar : public vtkstd::vector<int> // error on some compilers
{
};
The only portable fix, was to change it to this:
---vtkFoo.h----
class vtkFooBar;
class vtkFoo
{
private:
vtkFooBar* Bar;
};
---vtkFoo.cxx---
class vtkFooBar : public vtkstd::vector<int>
{
};
>Why not declare them as member classes of vtkFoo instead of
>making really long classnames?
>class vtkFoo
>{
> private:
> class Bar {
> }
>};
>
>Inside member functions of vtkFoo, you don't need to type
>vtkFooBar, just Bar. If declared as private members (as
>above) no one can use this class externally. If declared
>as public members, then others can reference the class
>name as vtkFoo::Bar.
>
> David
More information about the vtk-developers
mailing list