Attention: Answers.ros.org is deprecated as of August the 11th, 2023. Please visit robotics.stackexchange.com to ask a new question. This site will remain online in read-only mode during the transition and into the foreseeable future. Selected questions and answers have been migrated, and redirects have been put in place to direct users to the corresponding questions on Robotics Stack Exchange. Additional details are available here.
Move the main loop functionality from display(). This should stay in main.
You have a double main loop (ros::spin() implements one), but only one is called as no one calls display().
Put the main loop from display() where ros::spin() is and call pointCloud.display() from there.
Move the loop_rate part also there and uncomment it, it should work.