I am using VTK to do something, but my question could be general.

In VTK version < 6.0, a class vtkPolyDataMapper has a member function called SetInput, but in its version 6.0, it is changed to SetInputData. So in version 6, I have to,

vtkSmartPointer<vtkPolyDataMapper> polyDataMapper 
    = vtkPolyDataMapper::New();

polyDataMapper->SetInputData(polyData);
// polyDataMapper->SetInput(polyData);

Ideally, I was hoping this situation could be handled as easy as

if (vtkVersion::GetVTKMajorVersion() < 6)
{
    plane->SetInput(rgrid);
}
else
{
    plane->SetInputData(rgrid);
}

But you know this is not correct, so my question is: what is the best way in C++ to handle this situation.

有帮助吗?

解决方案

As you seem to know, you can't let the choice be made at runtime, because compilation will fail.

Instead, you can take advantage of the preprocessor to pass the correct code to the compiler. This is possible because VTK exposes its version in a preprocessor macro for you:

#if (VTK_MAJOR_VERSION < 6)
plane->SetInput(rgrid);
#else
plane->SetInputData(rgrid);
#endif
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top