我创建了一个类,并将其拆分为源文件和头文件,但我无法让它们相互通信。
我的头文件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错误。这可能是什么原因造成的?我似乎记得有一次通过添加一堆分号来解决类似的问题,但这一次似乎不起作用。
发布于 2012-04-28 02:24:58
想明白了!我把这个放在这里以防它能帮到什么人。
我必须将GridLayout.h设置为在某个时刻进行编译,然后将其改回,因为目录中有一个GridLayout.gch。所以编译器一定是直接忽略了.h。我删除了那个文件,现在它显示了我代码中的所有真正错误。
发布于 2012-04-25 05:14:29
您的“实际头文件”包含默认构造函数的两个声明:
public:
GridLayout();
GridLayout();您应该删除其中一个。
编辑:现在您在标题的末尾缺少了一个#endif,而在.cpp文件的末尾却多了一个...
https://stackoverflow.com/questions/10305791
复制相似问题