Search code examples
c++catkin

c++ error: expected class-name before '{' token


screenshot of Pose.hpp I am trying to catkin_make a simple package and I am getting the error

.../Pose.hpp:17:1: expected class-name before token...
.../Odometry.cpp:12:3: expected class-name before token...

The responsible Pose header file is sampled here as:

#ifndef POSE_HPP
#define POSE_HPP
#include <string>
#include <vector>
#include <ostream>
#include "ros/serialization.h"
#include "ros/builtin_message_traits.h"
#include "ros/message_operations.h"
#include "ros/message.h"
#include "ros/time.h"


namespace turtle
{//line 17
template <class ContainerAllocator>
struct Pose_ : public ros::Message
{
  typedef Pose_<ContainerAllocator> Type;

}; // struct Pose
...
} // namespace turtle

while on the referred header file is referenced in odometry.cpp shown as

#include <geometry_msgs/TwistWithCovarianceStamped.h>
#include <tf/transform_datatypes.h>
#include <robot_localization_demo/odometry.hpp>

namespace robot_localization_demo {

  TurtleOdometry::TurtleOdometry(ros::NodeHandle node_handle, double frequency):
    node_handle_{node_handle},
    turtle_pose_subscriber_{node_handle_.subscribe("turtle1/pose", 16, &TurtleOdometry::turtlePoseCallback, this)},
    turtle_twist_publisher_{node_handle_.advertise<geometry_msgs::TwistWithCovarianceStamped>("turtle1/sensors/twist", 16)},
    frequency_{frequency},
  {//line 12
    ;
  }

and odometry includes Pose as well. what am I missing here?


Solution

  • The official documentation for ros::Message says:

    This base-class is deprecated in favor of a template-based serialization and traits system.

    In the official source code it looks like it's still defined, but in a contrib version I found, the whole class definition is removed by #if 0:

    namespace ros {
    #if 0
    class Message {
        //
    };
    #endif
    }
    

    So, you most probably need to find a different base class.