繁体   English   中英

在名称空间/头文件中找不到类

[英]Can't find class in a namespace / header file

我创建了一个类,并将其拆分为源文件和头文件,但是我无法让他们互相交谈。

我的头文件GridLayout.h看起来像这样:

#ifndef GRIDLAYOUT_H_INCLUDED
#define GRIDLAYOUT_H_INCLUDED

#include <vector>
#include <types.h>
#include "GridPlaceable.h"

namespace Spaceships {

class GridLayout {
    //consider replace with std::list
    typedef std::vector<GridPlaceable*> column;

    public:
        GridLayout();
        ~GridLayout();

        void arrange();
        void splitColumn(size_t colNo, distance position);
        void splitRow(size_t rowNo, distance position);
        bool placeOne(GridPlaceable* thatOne);

private:
        bool tryToFit(GridPlaceable* thatOne, size_t startCol, size_t startCell);

        std::vector<column> wholeGrid;
        std::vector<GridPlaceable*> toPlace;

        std::vector<distance> rowHeights, colWidths;
        std::vector<size_t> firstEmpties;

        bool mandates;
};

};

GridLayout.cpp看起来像:

#include "GridLayout.h"

namespace Spaceships {

GridLayout::GridLayout() {

}

//GridLayout::aBunchOfOtherFunctions() { }

}

#endif

当我编译时,我得到了一大堆的GridLayout does not name a type错误。 是什么原因造成的? 我似乎记得曾经通过添加一堆分号来解决类似的问题,但这一次似乎并不起作用。

您的“实际头文件”包含默认构造函数的两个声明:

public:
    GridLayout();
    GridLayout();

您应该删除其中之一。

编辑 :现在您在标题的末尾缺少一个#endif ,并且在.cpp文件的末尾有一个太多...

弄清楚了! 我将其放在此处,以防它对某人有所帮助。

我必须将GridLayout.h设置为在某个时候进行编译,然后再将其更改回去,因为目录中存在一个GridLayout.gch。 因此,编译器一定会直接这样做并且完全忽略了.h。 我删除了该文件,现在它向我显示了代码中的所有实际错误。

暂无
暂无

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

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