包含的类类型显然没有声明,为什么?
Included Class Type is apparently not declared, why?
编译器抛出了以下问题:
include/FlowChannel.h:14:21:错误:"LatticeCell"未在此范围内声明 标准::矢量网格;
当有这 3 个头文件(LatticeCell.h
、FlowChannel.h
和Utilities.h
(和 2 个包含它们的 cpp 文件(lbm.cpp
和Utilities.cpp
(:
LatticeCell.h
#ifndef LATTICECELL_H
#define LATTICECELL_H
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
/* Single cell */
using namespace std;
class LatticeCell{
private:
std::vector<double> matrix = {0,0,0,0,0,0,0,0,0};
unsigned int type; //fluid, no-slip, velocity or density
public:
//Constructor
LatticeCell(unsigned int inType){
type = inType;
}
};
#endif
FlowChannel.h
#ifndef FLOWCHANNEL_H
#define FLOWCHANNEL_H
#include <vector>
#include <string>
#include <cmath>
#include <iostream>
#include "LatticeCell.h"
using namespace std;
class FlowChannel{
private:
std::vector<LatticeCell> grid; //ERROR LINE
unsigned int dimX = -1;
unsigned int dimY = -1;
public:
FlowChannel(unsigned int nx, unsigned int ny){
dimX = nx+2;
dimY = ny+2;
unsigned int gridSize = dimX*dimY;
grid.reserve(gridSize);
initGrid(/*TODO Params*/);
}
};
#endif
lbm.cpp
#include <string>
#include <vector>
#include "LatticeCell.h"
#include "FlowChannel.h"
#include "Utilities.h"
int main(int argc, char** argv){
printsomething();
return 0;
}
Utilities.cpp
#include "LatticeCell.h"
#include "FlowChannel.h"
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
void printsomething(){
cout << "something" << std::endl;
}
double calcRelaxationTime(unsigned int ny , double reynolds, double uin){
return 3.0 * (uin * ny / reynolds) - 0.5;
}
Utilities.h
#ifndef UTILITIES_H
#define UTILITIES_H
#include "LatticeCell.h"
#include "FlowChannel.h"
#include <vector>
#include <cmath>
void printsomething();
#endif
此外,我的编译器标志是:
-Wall -std=c++17 -pedantic
出于某种原因,我无法弄清楚,为什么LatticeCell
不会成为FlowChannel
中声明的类,因为它被包括在内。你们知道怎么了吗?
编辑:我添加了lbm.cpp
,Utilities.cpp
和Utilities.h
,所以你们看到了问题的全部范围
您应该检查文件是否在同一目录中。 我在VS 2019中复制并粘贴您的代码,它对我有用, 这是图片 流道晶格单元
似乎,删除#include 'LatticeCell.h'
除FlowChannel.h
之外的任何地方。老实说,我没有 100% 收到错误,因为这不会立即导致会导致此类错误的包含循环,但它有效。
相关文章:
- 为什么在定义函数之前先声明它
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- 为什么我必须在C++中添加一个赋值符号来声明一个数组
- 为什么C++编译器没有检测到正确声明的类?
- 包含的类类型显然没有声明,为什么?
- 为什么我必须以这种方式声明指针?
- 为什么我们将单个或多维数组的大小声明为常量值?
- 为什么函数声明中允许 const?
- 如果 x.h 仅由函数声明组成,为什么有必要在 x 中包含 x.h.cpp
- 为什么即使我声明了朋友类,我也会收到错误"无法访问类中声明的私人成员"
- 为什么 C++ 中的以下结构声明会导致退出 127?
- 为什么在我的 main 函数中声明整数后我的整数数组中会出现错误?
- 为什么转换函数声明不需要至少一个定义类型说明符
- 我无法正确获取这些变量声明...为什么这些参数不起作用?我只是将 n 值设置为数组长度
- 默认参数声明:为什么默认字符串参数必须是 const
- 声明和带有定义的声明.为什么不允许这样做
- 类作为模板参数的前向声明.为什么会这样呢?
- 语法错误:需要声明.为什么gsoap不能读取vector