【问题标题】:Compiler error message error:expected ')' before '*' token. Error with my constructor编译器错误消息错误:在 '*' 标记之前应为 ')'。我的构造函数出错
【发布时间】:2013-06-11 13:58:24
【问题描述】:

我不断收到以下编译器错误

在包含的文件中 /home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/src/BasicControllerState.cpp:1:0: /home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/include/state_machine_planner/BasicControllerState.h:38:49: 错误:在“*”标记之前应为“)”
/home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/src/BasicControllerState.cpp:4:44: 错误:预期的构造函数、析构函数或“(”之前的类型转换 令牌包含在文件中 /home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/include/state_machine_planner/StateMachinePlanner.h:16:0, 来自/home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/src/ControllerNode.cpp:4: /home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/include/state_machine_planner/BasicControllerState.h:38:49: 错误:在“”标记之前的预期“)” make[3]: [CMakeFiles/state_machine_planner.dir/src/BasicControllerState.cpp.o] 错误 1 ​​make[3]: * Waiting for unfinished jobs.... 在文件中 包括从 /home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/include/state_machine_planner/StateMachinePlanner.h:16:0, 来自/home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/src/StateMachinePlanner.cpp:1: /home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/include/state_machine_planner/BasicControllerState.h:38:49: 错误:在“*”标记之前应为“)”
/home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/src/StateMachinePlanner.cpp: 在构造函数中 'state_machine_planner::StateMachinePlanner::StateMachinePlanner()':
/home/armon/Development/groovy_workspace/sandbox/smart_wheelchair/trunk/smart_wheelchair/state_machine_planner/src/StateMachinePlanner.cpp:9:30: 错误:调用不匹配 '(state_machine_planner::BasicControllerState) (costmap_2d::Costmap2DROS*&)’

BasicControllerState 是 StateMachinePlanner 的成员

这里是代码,

BasicControllerState.h(相关部分):

class BasicControllerState {
                public:
                        BasicControllerState(){}
                        BasicControllerState(costmap_2d::costmap2DROS* costmap_ros);

基本控制器状态.cpp:

#include <state_machine_planner/BasicControllerState.h>

namespace state_machine_planner {
        BasicControllerState::BasicControllerState(costmap_2d::costmap2DROS* costmap_ros) {
                //init trajectory parameters specific to what state the child class     represents  

                //init sim_time_ and sim_granularity_
                //init sample space limits
                //init best_score_thresh_

                obstacle_dist_cost_gain_ = 0.1;
                heading_diff_cost_gain_ = 0.0;
                linear_vel_cost_gain_ = 0.0;
                omega_cost_gain_ = 0.0;

                num_of_linvel_samples_ = 20;
                num_of_angvel_smaples_ = 40;

                costmap_ros_ = costmap_ros;
                costmap_ros_->getCostmapCopy(costmap_);
                robot_footprint_ = costmap_ros_->getRobotFootprint();
                world_model_ = new base_local_planner::CostmapModel(costmap_);
        }

StateMachinePlanner.h:

class StateMachinePlanner
        {
                public:
                        StateMachinePlanner();
                        void init(int latency_command_queue_size, vel_params_struct vps, time_params_struct tps);
                        void setKey(key_command_t key);
                        geometry_msgs::Twist computeVelocityCommands();
                private:
                        std::deque<Eigen::Vector2f> latency_command_queue_;
                        int latency_command_queue_size_;
                        vel_params_struct velocity_parameters_;
                        time_params_struct time_parameters_;
                        navigation_state_t current_state_;
                        key_command_t key_command_;
                        tf::TransformListener* tf_;
                        costmap_2d::Costmap2DROS* costmap_ros_;
                        costmap_2d::Costmap2D costmap_;

                        BasicControllerState forward_state_;

StateMachinePlanner.cpp(我在其中实例化它):

namespace state_machine_planner {

        StateMachinePlanner::StateMachinePlanner() : tf_(NULL), costmap_ros_(NULL) {
                tf_ = new tf::TransformListener(ros::Duration(10));
                costmap_ros_ = new costmap_2d::Costmap2DROS("costmap",*tf_);
                costmap_ros_->getCostmapCopy(costmap_);
                forward_state_(costmap_ros_);
        }

请原谅我,我知道这可能看起来微不足道,但我希望能找到一些 c++ 向导来拯救我。在这一问题上花费了太长时间。

【问题讨论】:

  • 你是否包含了相关的标题?
  • 区分大小写:costmap_2d::costmap2DROS != costmap_2d::Costmap2DROS
  • 是的,我确实有所有相关的标题
  • 凯西,你是一个美丽的人,我祝你生活中的所有快乐

标签: c++ ros


【解决方案1】:

costmap_2d::costmap2DROS* 需要前向声明,或者您需要在定义它的位置包含头文件。因为它是一个指针,所以前向声明更好。所以在类定义之前这样做:

namespace costmap_2d{
  class costmap2DROS;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多