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