Given that you are following this. Make sure you have the correct headers and in the CMakeLists.txt you have included tf2_ros and tf2.