문제

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