2012-10-23 43 views
0

我宣布这个类 '机器人':静态常量不可访问的类定义(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”(在第9行中声明的 “e:\文件\视觉工作室2012 \项目\机器人运动学\机器人运动学\ Robot.h”)为i naccessible E:\文档\的Visual Studio 2012 \项目\机器人运动学\机器人运动学\ Robot.cpp 10个43个机器人运动学

回答

2

float* forwardKinematics(int theta[Robot::N_ROBOT_JOINTS])声明了一个免费的功能,而不是一个成员,所以它并没有进入Robot的私生子。

你可能是指

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

这告诉编译器您正在实施的成员,从而允许访问类的私处。

+0

感谢ü乌拉圭回合帮助Robot一员,工作! ;) –

1

如果forwardKinematics是你需要把在.cpp文件

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