类定义中的静态Const无法访问(C ++)

时间:2012-10-23 11:06:19

标签: visual-c++

我已经宣布这个类'机器人':

 #ifndef ROBOT_H
 #define ROBOT_H

 class Robot {

 private:

    static const int N_ROBOT_JOINTS = 5;    
    static const int JOINT_PARAM_D1 = 275;  
    static const int JOINT_PARAM_A2 = 200;  
    static const int JOINT_PARAM_A3 = 130;  
    static const int JOINT_PARAM_D5 = 130;

 public:        
    Robot();
    float* forwardKinematics(int theta[N_ROBOT_JOINTS]);

 };

 #endif

Robot.cpp

#include "stdafx.h"
#include "Robot.h"
//#define _USE_MATH_DEFINES
//#include <math.h>

Robot::Robot(void)
{
}

float* forwardKinematics(int theta[Robot::N_ROBOT_JOINTS])
{
    float* array_fwdKin = new float[Robot::N_ROBOT_JOINTS];

    float p_x, p_y, p_z, pitch, roll;

    for (int i = 0; i < Robot::N_ROBOT_JOINTS; i++)
    {

    }

    return array_fwdKin;
}

但是当我尝试编译时我得到了这个错误:

  

6智能感知:成员“机器人:: N_ROBOT_JOINTS”(在“e:\ documents \ visual studio 2012 \ projects \ robotics kinematics \ robotics kinematics \ Robot.h”第9行声明)无法访问e:\ Documents \ Visual Studio 2012 \ Projects \ Robotics Kinematics \ Robotics Kinematics \ Robot.cpp 10 43机器人运动学

2 个答案:

答案 0 :(得分:2)

float* forwardKinematics(int theta[Robot::N_ROBOT_JOINTS])声明一个自由函数,而不是成员,因此它无权访问Robot的私有函数。

你可能意味着

float* Robot::forwardKinematics(int theta[Robot::N_ROBOT_JOINTS])
//       |
//  notice qualification

这告诉编译器你正在实现该成员,因此允许访问类'privates。

答案 1 :(得分:1)

如果forwardKinematicsRobot的成员,则需要输入.cpp文件

float * Robot::forwardKinematics( int theta[Robot::N_ROBOT_JOINTS] )
{
      // implementation
}
相关问题