我创建了一个类并将其拆分为源文件和头文件,但我无法让它们相互通信。
我的头文件 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();
您应该删除其中一个。
编辑:现在您在 header 末尾缺少一个#endif
,而在.cpp
文件...
关于c++ - 在命名空间/头文件中找不到类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10305791/