简体   繁体   English

C++ 未知类型名称,即使类型是通过标头定义的

[英]C++ Unknown type name even though type is defined through headers

This is driving me insane, I have a class called Model, a class called View, and a header file for something GameCommand.这让我发疯了,我有一个叫做 Model 的类,一个叫做 View 的类,还有一个 GameCommand 的头文件。 I've included the right header guards and everything as far as I can tell but I keep getting an unknown type name error据我所知,我已经包含了正确的标题守卫和所有内容,但我不断收到未知类型名称错误

Model.h模型.h

#ifndef MODEL_H
#define MODEL_H

class Model
{
public:
    Model(); //default constructor
};

#endif

Model.cpp模型.cpp

#include "Model.h"
#include <iostream>
using namespace std;

Model::Model() //default constructor
{
whatever
}

View.h查看.h

#ifndef VIEW_H
#define VIEW_H

class View
{
public:
    View(); 
};

#endif

View.cpp查看.cpp

#include "View.h"
#include <iostream>
using namespace std;

View::View()
{ whatever
}

GameCommand.h游戏命令.h

#ifndef GAMECOMMAND_H
#define GAMECOMMAND_H
#include "Model.h"
#include "View.h"

void DoGoCommand(Model&, View&);
error: unknown type name 'Model'
void DoGoCommand(Model&, View&);
                 ^
error: unknown type name 'View'
void DoGoCommand(Model&, View&);
                         ^

I feel like I've tried everything, is there something I am just not seeing here?我觉得我已经尝试了一切,有什么我在这里没有看到的吗?

You can try to forward declare the classes.您可以尝试转发声明类。

class Model;类模型;

class View;类视图;

in your GameCommand.h在你的 GameCommand.h

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM