在命名空间/头文件中找不到类
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。我删除了该文件,现在它向我显示了代码中的所有真正错误。
相关文章:
- C++ ZBar cmake 错误"找不到文件"时包括
- 如何修复使用VScode调试器gcc调试时的"找不到文件"错误
- C++找不到文件
- Windows Subsystem for Linux (WSL) 下的间歇性随机"找不到文件"错误
- Makefile在Linux中工作,但在Windows下不起作用,在子目录中找不到文件
- Nemiver 找不到文件 /build/glibc-LK5gWL/glibc-2.23/stdlib/random.c
- 在 Windows 10 上找不到 ./****.h 文件 qt5,C++
- 找不到文件或目录
- ld:找不到文件:/usr/lib/crt1.o
- sip:找不到文件"QtGui/QtGuimod.sip"
- 生成文件错误 - 找不到文件 - *.cpp
- 错误53:找不到文件,而是路径中存在所有DLL
- YAML::LoadFile(std::string const&) 找不到文件 [ROS 中的 yaml-cpp]
- 在英特尔C++编译器 (Linux) 的配置搜索路径中找不到文件可执行文件
- CMake 包含错误(找不到文件、未定义引用)
- 尝试包含id3lib标头时出现找不到文件错误
- 在iOS设备上找不到文件QT创建者C QstandardPaths :: StandardLocations(Qs
- 生成可执行文件时找不到文件,但在eclipse c 中运行正常
- Rcpp:将C++函数移植到 R 中,'Rcpp.h'找不到文件
- CodeBlocks MinGW版本找不到文件,必须手动包含在链接器中