C ++不将名称命名为类型 [英] C++ Does not name to a type

查看:147
本文介绍了C ++不将名称命名为类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个容易的问题,但我不知道为什么编译器它给我这个错误。我有两个类。代理和环境。当我尝试添加一个类型的代理在我的环境类中的对象我得到代理不命名为类型错误。我在我的Environment.h类中包括Agent.h

This might be an easy question, but I cannot figure out why the compiler it's giving me this error. I have two classes. Agent and Environment. WHen I try to add an object of type Agent in my Environment class I get Agent does not name to a type error. I am including Agent.h in my Environment.h class

#ifndef AGENT_H_INCLUDED
#define AGENT_H_INCLUDED

#include <vector>
#include <iostream>
#include "Environment.h"

using namespace std;

class Agent{
    public:
        Agent(bool s);
        vector<int> getPercept();
        void setPercept(vector<int> p);
        void goForward();
        void turnRight();
        void turnLeft();
        void clean();
        void paint();
        void refuel();
        bool needsRefuel();
        void turnOn();
        void turnOff();
        bool isActive();
        void move();
        int getCurX();
        int getCurY();
        char getCurDir();
        void setCurrentPosition(int x, int y, char d);


    private:
        vector<int> percept;
        int actions;
        int performance;
        char direction;
        bool isOn;
        int curX;
        int curY;
        char curDir;
};

#endif // AGENT_H_INCLUDED

/ ** * ** ** * ** * b

/*************************/

#ifndef ENVIRONMENT_H_INCLUDED
#define ENVIRONMENT_H_INCLUDED

#include <vector>
#include <iostream>
#include "Agent.h"

using namespace std;


class Environment{
    public:

        Environment(vector<vector<char> > roomData);
        Environment(vector<vector<char> > roomData, vector<int> status);
        void setRoomData(vector<vector<char> > roomData);
        bool isSimulationComplete();
        void isAgentHome();
        vector<int> sendLocationStatus();
        void printEnvironment();
        void setAgentHome(int x, int y);
        vector<int> getAgentPercept();
        void setAgentPercept(vector<int> status);
        void setAgentPosition(int x, int y, char p);
        vector<int> sendAgentPercept();
        void calculateAgentPercept();


    private:
        vector<vector<char> > room;
        vector<int> agentPercept;
        bool simulationComplete;
        int agentHomeX;
        int agentHomeY;
        int agentX;
        int agentY;
        char agentDir;
        Agent agent;   ////ERROR IS HERE
};

#endif // ENVIRONMENT_H_INCLUDED


推荐答案

您的代理.h包括environment.h。 agent.h文件按照从上到下的顺序解析,因此当解析environment.h时,编译器不知道代理是什么。似乎没有理由在agent.h中引入environment.h。

Your agent.h includes environment.h. The agent.h file is parsed in order from top to bottom, so when environment.h is parsed, the compiler doesn't know what an Agent is. There appears to be no reason to incude environment.h in agent.h.

这篇关于C ++不将名称命名为类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆