Obl*_*ons 1 c++ namespaces class header-files
我创建了一个类并将其分成源文件和头文件,但我无法让它们相互交谈。
我的头文件,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;
};
};
Run Code Online (Sandbox Code Playgroud)
GridLayout.cpp
好像:
#include "GridLayout.h"
namespace Spaceships {
GridLayout::GridLayout() {
}
//GridLayout::aBunchOfOtherFunctions() { }
}
#endif
Run Code Online (Sandbox Code Playgroud)
当我编译时,我收到一大堆GridLayout does not name a type
错误。可能是什么原因造成的?我似乎记得曾经通过添加一堆分号来解决类似的问题,但这一次似乎不起作用。
您的“实际头文件”包含默认构造函数的两个声明:
public:
GridLayout();
GridLayout();
Run Code Online (Sandbox Code Playgroud)
您应该删除其中之一。
编辑:现在您#endif
在标题末尾缺少一个,并且在文件末尾有太多.cpp
...