我創建了一個類並將其分割爲源文件和頭文件,但我無法讓它們相互交談。在名稱空間/頭文件中找不到類
我的頭文件,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
錯誤的整體轉換。什麼可能導致這個?我似乎還記得曾經拋出一堆分號來解決類似的問題,但這次似乎並不奏效。
這聽起來像你要我們幫助你的語法錯誤。在這種情況下,您需要發佈* real *代碼,否則我們最終會追逐無關緊要的問題。 – 2012-04-24 20:52:24
是真碼嗎?你在類定義,構造函數聲明,命名空間聲明之後缺少';' – EdChum 2012-04-24 20:57:29
@EdChum,命名空間分號是可選的。 – chris 2012-04-24 20:58:24