繁体   English   中英

类未命名类型错误

[英]Class does not name a type error

我在项目中有以下代码:

    #ifndef MAP_H
    #define MAP_H

    #include <string>
    #include "MapCell.h"

    using namespace std;

    class Map{
    public:
        Map();
        Map(int, int);
        Map(string);
        virtual ~Map();
    private:
        int grid_size;
        MapCell * grid;

    };

    #endif

当我进行编译时,当我注释掉MapCell *网格并从main运行以下代码块时,出现错误“错误:'MapCell'未命名类型”:

#include <iostream>
#include <cstdlib>

#include "MapCell.h"

using namespace std;


int main() {

    MapCell * test_var;

    test_var = new MapCell();

    delete test_var;


    cout << "Press enter to end process...";
    cin.get();
    cin.get();
    return 0;
}

一切正常。 我知道我的MapCell.h和.cpp文件在正确的位置,并且我猜编译器可以看到它们,因为它可以从main运行。 我阅读了一些其他问题,大多数答案似乎都指向语法错误或正向声明,这些实际上并不适合此处(除非我忽略了某些内容)

对这里发生的事情有什么想法吗?

克里斯和伟大的狼带我找到了解决问题的解决方案。 我需要向前声明我的MapCell类,以便编译器能够链接到整个类。

暂无
暂无

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

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