질문 (질문 아래 답)오류 C2061 : 구문 오류 : 식별자 '로봇'
난 내 같은 질문을 많이 알고 있지만, 어쨌든 내 문제에 대한 해결책을 찾지 못했습니다. #include "robot.h"
interface.h 로하고 interface.h 에 초기화 기능에 , Robot* _robot
추가 : 학교 및 모두를위한 작은 프로젝트를 작성
I'w 내가 추가 할 때까지 문제없이 실행되었다.
저는 Visual Studio 2013 Ultimate (전 학생입니다))으로 작성하고 있습니다. 전체 코드는 github에 액세스 할 수 있으며 사람들은 나에 의해 작성된 파일입니다
- allegroHelper.h의 통화 당 - 인터페이스 를 그리기위한 클래스 - 사용 편의성 알레그로 라이브러리
- interface.h의 cpp를위한 몇 가지 기능
- logic.h의 통화 당 - 로봇의 논리
- robot.h .CPP - 로봇 클래스
- libs와/xkontiTextUtils.h 통화 당 - 일부 공상 콘솔 기능 (일부가 파손되는)
- libs와/xkontiVector2d.h .cpp - 작은 vec 토르 클래스
내 코드를 깨는 것은이있다 :
//interface.h
#pragma once
//////////////////////////////////////////
// INCLUDES
//////////////////////////////////////////
#include <string>
#include <vector>
#include "libs/xkontiTextUtils.h"
#include "libs/xkontiVector2d.h"
#include <allegro5/allegro.h>
#include "allegro5/allegro_image.h"
#include <allegro5/allegro_primitives.h>
#include "robot.h"
//#include "allegroHelper.h" // Not needed due to forward declatation?
//////////////////////////////////////////
// INTERFACE CLASS
//////////////////////////////////////////
class Interface {
public:
Interface();
~Interface();
bool init(std::string _mapPath, int _width, XkontiConsoleColors* _con, Robot* _robot);
(...)
Robot* robot;
(...)
};
로봇 클래스는 robot.h에 있습니다
//robot.h
#pragma once
//////////////////////////////////////////
// INCLUDES
//////////////////////////////////////////
#include <iostream>
#include <vector>
#include <math.h>
#include "libs/xkontiTextUtils.h"
#include "libs/xkontiVector2d.h"
#include <allegro5/allegro.h>
#include "allegro5/allegro_image.h"
#include <allegro5/allegro_primitives.h>
#include "allegroHelper.h"
//////////////////////////////////////////
// ROBOT CLASS
//////////////////////////////////////////
class Robot {
public:
// Constuctor & Destructor
Robot(std::vector< std::vector<bool> >& _map);
~Robot();
// Initialization functions
void initBody(Vector2D _size, Vector2D _pos, double _rotation, double _maxVelocity, double _maxAVelocity);
void initHead(Vector2D _pos, Vector2D _rotRange, double _rangeMin, double _rangeMax, double _rangeError, unsigned int _resolution, double _rangeLess, double _rangeOver);
// Set Functions
void setPos(Vector2D _newPos);
void setPos(double _x, double _y);
void setRotation(double _rad);
// Get Functions
Vector2D getPos();
Vector2D getHeadPos();
double getRotation();
int getStatus();
// Commands Functions
void move(double _dist); // Move robot forward by specified distance
void move(double _dist, double _rad); // Move and turn robot
void turn(double _rad); // Turn robot by specified degree value
std::vector<double>& scan(); // Scans terrain. Returns reference to vector of distances.
// Periodical Functions
void update(double dt);
void draw(double dt);
// Public Variables
std::vector<Vector2D> scanPoints;
private:
// Body functions
// Head functions
double trace(double _rad); // Measure distance from current position
// Outside pointers
std::vector< std::vector<bool> >& map;
// Body properties
Vector2D size; // Dimensions: Width, Length
Vector2D pos; // Position: X, Y
double rotation; // Rotation: Z axis
double leftDistance; // Distance left to travel
double leftRotation; // Rotation left to rotate
double maxVelocity; // Max forward velocity
double maxAVelocity; // Max angular velocity on Z axis (left/right)
// Head properties
Vector2D headPos; // Head position: X, Y
Vector2D headRotRange; // Head Z rotation range: from - to in deg
double rangeMin; // Minimum and Maximum detection range
double rangeMax;
double rangeError; // Error percentage on range measuring
unsigned int resolution; // Number of traces in left/right scan
double rangeLess; // Number used when something was nearer than rangeMin
double rangeOver; // Number used when nothing was detected
};
내가 컴파일러에서지고있어 오류 :
1>------ Build started: Project: RoboSim, Configuration: Debug Win32 ------
1> robot.cpp
1>d:\xkonti\github\robosim\interface.h(28): error C2061: syntax error : identifier 'Robot'
1>d:\xkonti\github\robosim\interface.h(39): error C2143: syntax error : missing ';' before '*'
1>d:\xkonti\github\robosim\interface.h(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> logic.cpp
1>d:\xkonti\github\robosim\interface.h(28): error C2061: syntax error : identifier 'Robot'
1>d:\xkonti\github\robosim\interface.h(39): error C2143: syntax error : missing ';' before '*'
1>d:\xkonti\github\robosim\interface.h(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> xkontiVector2d.cpp
1> Generating Code...
1> Skipping... (no relevant changes detected)
1> interface.cpp
1> allegroHelper.cpp
1> RoboSim.cpp
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
원형 #include
에 의존하지만, 위해 :
- 나는 모든 헤더에
#pragma once
을 사용하여 내가 포함 것을 발견 - interface.h을 interface.h 에 allegroHelper.h allegroHelper.h및 오랫동안 문제없이 컴파일하고있었습니다.
내가 뭘 잘못하고 있는지 말해 줄 수 있습니까? 또는 어떤 힌트를 확인할 것인가?
답변
좋아. 많은 시간이 없으며 Interface에서 Robot 클래스에 대한 포인터를 가질 방법을 찾지 못해서 Robot 클래스의 일부 데이터를 참조하여 데이터에 액세스하고 있습니다.주요 파일에서
: 인터페이스 클래스에서
//RoboSim.cpp
std::vector< std::vector<bool> > map;
std::vector<Vector2D> scanPoints;
ALLEGRO_BITMAP* image = nullptr;
(...)
Interface inter = Interface(scanPoints);
Robot robot = Robot(map, scanPoints);
(...)
:
//interface.h
(...)
class Interface {
public:
Interface(std::vector<Vector2D>& _scanPoints);
~Interface();
(...)
private:
XkontiConsoleColors* con;
std::vector<Vector2D>& scanPoints;
(...)
로봇 클래스에서 :
나는이 문제를 확인하기 위해 프로젝트에 파고했다//robot.h
(...)
class Robot {
public:
// Constuctor & Destructor
Robot(std::vector< std::vector<bool> >& _map, std::vector<Vector2D>& scanPoints);
~Robot();
(...)
std::vector< std::vector<bool> >& map;
std::vector<Vector2D>& scanPoints;
(...)
컴파일러는 '로봇'이 무엇인지 모르는 것을 알려줍니다. '로봇'은 어디에 정의되어 있습니까? – Casey
나는 한 번 #pragma를 사용하지는 않았지만, .h 주위에 #ifndef, #define, #endif를 만들었습니다. 각각 다른 이름을 얻었습니다. robot.h 게시하기 – Samhain
robot.h를 포스트에 추가했습니다. 이것은 세미콜론이 아닙니다 @ πάντα ῥεῖ – Xkonti