[英]C++, problems with structures in classes
everyone if someone can help me I'll be very grateful.大家如果有人可以帮助我,我将不胜感激。 I've been trying to fill in the structure called m_Center by a function of the same class, I'm using eclipse to work and it gave the next errors messages:我一直在尝试通过同一个 class 的 function 填充名为 m_Center 的结构,我正在使用 eclipse 工作,它给出了下一个错误消息:
-'m_Center' was not declared in this scope
-Field 'radius' could not be resolved
-Symbol 'm_Center' could not be resolved
My header file is Obstacles.h
:我的 header 文件是Obstacles.h
:
#ifndef SRC_OBSTACLES_H_
#define SRC_OBSTACLES_H_
#include <eigen3/Eigen/Dense>
#include <iostream>
#include <random>
#include <list>
#include <stdlib.h>
#include <time.h>
class CObstacles
{
protected:
struct Center
{
float m_vXdCenterX;
float m_vXdCenterY;
float m_vXdCenterZ;
double distance;
Eigen::VectorXf v_XfAxisCyl;
Eigen::VectorXf vXfP1;
double radius;
};
Center m_Center;
public:
CObstacles(double dradius, Eigen::VectorXf &m_vXdMaxBound, Eigen::VectorXf &m_vXdMinBound, int num_obstacles);
~CObstacles();
void generate_obstacles(double dradius, Eigen::VectorXf &m_vXdMaxBound, Eigen::VectorXf &m_vXdMinBound, int num_obstacles);
};
#endif
while the Obstacles.cpp
is:而Obstacles.cpp
是:
#include "Obstacles.h"
CObstacles::CObstacles(double dradius, Eigen::VectorXf &m_vXdMaxBound, Eigen::VectorXf &m_vXdMinBound, int num_obstacles)
{
double m_dradius = dradius;
Eigen::VectorXf m_dvXdMaxBound = m_vXdMaxBound;
Eigen::VectorXf m_dvXdMinBound = m_vXdMinBound;
int dnum_obstacles = num_obstacles;
}
CObstacles::~CObstacles()
{
}
void generate_obstacles(double dradius, Eigen::VectorXf &m_vXdMaxBound, Eigen::VectorXf &m_vXdMinBound, int num_obstacles)
{
srand(time(NULL));
float aux_centerx, aux_centery;
Eigen::Vector3f vXfP1;
Eigen::Vector3f vXfP2;
Eigen::Vector3f distance;
for(int num_obs = 0; num_obs < num_obstacles; num_obs++)
{
aux_centerx = rand() % 20 + 1;
aux_centery = rand() % 20 + 1;
vXfP2 << aux_centerx, aux_centery, 0;
vXfP1 << aux_centerx, aux_centery, 0;
distance = vXfP2 - vXfP1;
m_Center[num_obs].radius = dradius;
}
}
Add the class name before the generate_obstacles method.在 generate_obstacles 方法之前添加 class 名称。
void CObstacles::generate_obstacles(double dradius, Eigen::VectorXf &m_vXdMaxBound, Eigen::VectorXf &m_vXdMinBound, int num_obstacles)
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.